Results 1 to 3 of 3

Thread: response.redirect.......

  1. #1
    Join Date
    Dec 1969

    Default response.redirect.......

    hi all,<BR> <BR> how do i use 2 submit buttons for the same form and also check to see which one was pressed also at the same time checking to see if the user has input the correct data.<BR><BR>if i specify action as "action=somepage.asp" and in somepage.asp file use the if.. else.. statements to check which button was pressed in the html can i check if the user has entered valid data and if so pass these values to "anotherpage.asp" for further processing. using response.redirect (as in response.redirect "anotherpage.asp"),i lose the form variable values. how do i get around this ?? also is there a better way of achieving this???<BR><BR>my code is something like this..<BR><BR>&#060;form name="sendinfo" action="somepage.asp" method ="post"&#062;<BR><BR>recipient&#039s E_mail Address:&#060;input name= recid size = 30 <BR>your Message:<BR>&nbsp;&#060;TEXTAREA cols=30 name=message rows=5 wrap=virtual&#062;&#060;/TEXTAREA<BR><BR>&#060;input type = "hidden" name="optbut"&#062;<BR>&#060;input type = "submit" name ="send" value ="Send"onclick=&#039document.sendinfo.optbut.value ="send"&#039&#062; <BR>&#060;input type = "reset" name= "erase" value ="Clear entries"&#062; <BR>&#060;input type = "submit" name = "preview" value="Preview" onclick=&#039document.sendinfo.optbut.value="Previ ew"&#039&#062; <BR> <BR> <BR>thanx in advance.<BR>-peter.

  2. #2
    David Mann Guest

    Default Whew! Now this one will take a bit of time, but he

    Okay, first order of business--getting two submits on the same form. Are you familiar with JavaScript? If so, let me share with you my tactics on form validation. The script I&#039ll provide for you below will work quite well for what you are doing, so let&#039s begin.<BR><BR>*********Form Validation!***********<BR>Before the user sends the form, you should validate it. Since VBScript can&#039t be interpreted by Netscape, you should use JavaScript, instead. Before the validation, however, let&#039s modify your script a bit:<BR><BR>&#060;form name="sendinfo" action="somepage.asp" method="post"&#062;<BR><BR>recipient&#039s E_mail Address:&#060;input name="recid" type="text" size="30"&#062; <BR><BR>your Message:<BR>&#060;TEXTAREA cols=30 name=message rows=5 wrap=virtual&#062;&#060;/TEXTAREA&#062;<BR><BR>&#060;input type="hidden" name="fAction"&#062;<BR>&#060;input type = "button" name="send" value="Send" onclick="checkForm(this.form, &#039send&#039)"<BR>&#060;input type = "button" name="preview" value="Preview" onclick="checkForm(this.form, &#039preview&#039)"&#062;<BR>&#060;input type = "reset" name= "erase" value ="Clear entries"&#062; <BR>&#060;/form&#062;<BR><BR>Okay! You&#039ll notice above that I created a new hidden field and replaced the input type="submit" tags with input type="button" tags, instead. Why&#039d I do this? Well, for starters, the submit button doesn&#039t really support the onClick event as well as the standard button type, AND you DO NOT NEED A SUBMIT BUTTON for form submission!! This gives you more control. <BR><BR>Now, you&#039ll notice I made a function call from the buttons and passed it two values. The first value in the function is the self-referencial pointer, this.form. This.form sends a pointer to the function that points to the whole form, thus allowing you access to ALL the form&#039s member objects. You&#039ll see how this works in a second with my validation script. <BR><BR>The second value in the function call is the value of the button itself, which the function will use to let your subsequent page know what type of action is being requested. There are many ways to do this, but this one seems best-suited to your current needs. Now, onto the script that handles the processing.<BR><BR>&#060;script language="JavaScript"&#062;<BR>function checkForm(form, action)<BR>{<BR>//handle validation and action processing here.<BR>//form is the actual form being passed in.<BR>//action is the value of the action type--either &#039send&#039 or &#039preview&#039<BR><BR>if (form.recid.value == "" &#124&#124 form.recid.value == " ")<BR>{<BR> alert("Please input your email address before continuing.")<BR>}<BR>//the above code will check for something in the email field.<BR>//it is VERY basic, and could be expanded, but it should work for now.<BR><BR>else<BR>{<BR>form.fAction.value = action<BR>form.submit()<BR>}<BR>}<BR>&#060;/script&#062;<BR><BR>Okay, now if you understand JavaScript, then the above should be very easy. If not, I shall explain. <BR><BR>If you know that you&#039re passing a reference to the whole form to the function via the this.form pointer, then you can access each form object&#039s value by using the form.objectName.value property. Some form fields have different properties and such that you can manipulate, as well, but this is a simple example, so I&#039ll not go into that too deeply here. Now, the form.submit()<BR>call is calling the form&#039s submit method which sends the data. See now why I said you don&#039t need submit buttons? =) <BR><BR>The reason I chose to show you this type of validation is that it is much cleaner and more efficent than calling a whole new page to do that processing for you, you know? The premise is that the javascript prevents the user from proceeding UNTIL he or she has entered valid data.<BR><BR>Okay, so that was step one. We have your validation in place, and we have the type of action that the user wishes to commit to done. On to the ASP processing!<BR><BR>NOTE: You CAN use the Request Object to retrieve a form button&#039s name and value! HOWEVER, in your case, this would be bad, for you do not know which button was CLICKED even though you&#039ll see both buttons&#039 names and values in the Request.Form collection. Just some food for thought...<BR><BR>&#060;%<BR>&#039somepage.asp<BR> <BR>Option Explicit<BR><BR>Dim sEmail, sMessage, sAction &#039vars for processing<BR><BR>sEmail = Request.Form("recid")<BR>sMessage = Request.Form("message")<BR>sAction = Request.Form("fAction")<BR><BR>&#039Here is where you will figure out where to redirect to, or whatever other processing you might need.<BR><BR>%&#062;<BR><BR>Okay, here&#039s the tricky part. A text area can contain special characters and many lines of text. I would normally suggest passing a querystring in your Response.Redirect, however, you might violate the size limitations of a query string. IF you limit the amount of things that the user can type into the Textarea, then you can get away with this method. Another way is to use a session object, but I&#039m not very fond of session objects simply because if your site is getting accessed a lot, this can really bog down your system. However, for the sake of simplicity, I will give you a solution based upon the Session object for now, simply because I cannot be sure that your text area will limit the amount of text inputted by the user. <BR><BR>&#060;%<BR>&#039continue somepage.asp&#039s code routines.<BR><BR>Session("Email") = sEmail<BR>Session("Message") = sMessage<BR>Session("Action") = sAction &#039used in case you don&#039t process the action on this page. <BR><BR>Response.Redirect("")<BR>Response.End<BR><BR>&#039end somepage.asp&#039s code routines<BR>%&#062;<BR><BR>Now to grab those session entries...<BR><BR>&#060;%<BR>&#039Anotherpage.asp< BR><BR>Option Explicit<BR><BR>Dim sEmail, sMessage, sAction<BR><BR>sEmail = Session("Email")<BR>sMessage = Session("Message")<BR>sAction = Session("Action")<BR><BR>&#039Do processing here.<BR><BR>&#039End anotherpage.asp code routines<BR>%&#062;<BR><BR>Okay, I hope this has helped you some, or given you some insight as to what you&#039d like to do. If you choose to use something other than Sessions, just take in consideration your limitations. These are, of course, very simple solutions, and be aware that there are MANY solutions to your problem. Let me know what you think, and if you want any more suggestions, I&#039ll be happy to write again. Good luck!<BR><BR>Sincerely,<BR> --David

  3. #3
    Join Date
    Dec 1969

    Default david ,mann ur quite a genius

    hi there david,<BR><BR> i&#039m truly delighted that someone&#039s been able to decipher what i was trying to do.right now i&#039m trying out ur idea.but true as u said that limiting the size of a of the textarea is difficult, just hope that the user has more commonsense than nonsense. if i do face any more probs i trust that u could help me out.thanx a million.<BR><BR> regards<BR> peter.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts