www.webdeveloper.com
Results 1 to 13 of 13

Thread: preserving input fields on a form

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Posts
    28

    preserving input fields on a form

    I have a .asp form page that submits to another .asp page that uses cdonts to send me an email and does a response.redirect back to the form page. I need to preserve (keep) a couple of text box values and a couple of dropdown box values. At this point I have global.asa variables for the fields in question and they are all set to null. I can't figure out how to put the contents back in the fields on the form, when it returns from the cdonts page. I assume that I must save all the field values in the session variables just prior to the submit to the cdonts page, but then what?

    If you can show me how to accomplich this for one text field called name and one dropdown box called PUDeliv (one option for pickup and one for delivery), it would be greatly appreciated.

    To get a better picture, go to www.faxfoodorder.com/newpage2.asp - This page submits to /get3.asp which retrieves all the form fields and sends an email using cdonts and then redirects back to newpage2.asp.

    Larry

    P.S. I use outlook, IE 6.0

  2. #2
    Join Date
    Feb 2003
    Posts
    2
    Larry,

    I grad all of the input request variable value and past them on to succeeding pages. I do this like:

    dim savReq
    savReq=Request.form

    One way to pass these on is:

    <form ...... Action="xxx.asp?<%=savReq%> .....>

    Another would be to save the values ("request.form") in a session variable.

    Then you may have to do some ASP coding to reload the variable values into the form, depending on how you loaded them initially. If you just start out with an empty form (not DB fed) then the textboxes will not be a problem You might have to "force" values into the dropdown boxes though.

    Ex. of textbox:

    <input type="text" name="xxx" value="<%=request("fieldname")%>" >

    First time it will be empty; on reentry it will have the previous value.

    This should give you some ideas....

    Larry Woods

  3. #3
    Join Date
    Feb 2003
    Posts
    28
    Hi Larry, thanks for your response. I have no problem passing the fields to the send email page and the send email does send me a valid email with all the form fields on it. I have tried doing the following which is similar to what you suggested:

    input type="text" name="Name" size="38" maxlength="35" value="<%=session("holdname")%>">

    I use a global.asa which initialized all the fields I need to keep - to null.

    In the form, just before the submit, I did the following:

    <%
    Session("holdname") = request.form("Name")
    %>

    The results in the name field are always blank when the form page redisplays. What do you think?

    How did you access savreq in the send mail page?

    In your statement below, should =request("fieldname") be
    =request.form("fieldname") ?????

    input type="text" name="xxx" value="<%=request("fieldname")%>" >

    Larry

  4. #4
    Join Date
    Feb 2003
    Posts
    2
    A couple of comments:

    First, there is really no reason that I can see for you to define the Session variable in global.asa. Just use it when you need to. Then set it to an empty string.

    As far as the email page is concerned, if you just pass the request variables as I showed you, you should be able to examine their values on the target page just as if they were controls on the previous page. I have exactly the same situation as you have, and I don't have any problems with interrogating the request values.

    Larry Woods

  5. #5
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    Ok to start with, don't abuse session variables for storing values to be passed to another page. What you are trying to do would be a lot easier if you post your form back to itself and have the form and the CDONTS in the same page.

    Code:
    <%
    validate = request.form("validate")
    if validate = "yes" then
    UserName = request.form("UserName")
        Set MailObject = Server.CreateObject("CDONTS.NewMail") 
        MailObject.From = "from@me.com" 
        MailObject.To = "to@me.com" 
       etc...................
       message = "Your email is sent"
    end if
    %>
    <form action="samepage.asp" method="get">
    <input name="Username" type="text" value="<%=username%>">
      <input name="validate" type="hidden" id="validate" value="yes">
      <input type="submit" name="Submit" value="Submit">
    <%=message%>
    </form>
    Now this is an example of how i would do this, but you can change it to suit yourself. There are different ways you can set this up the above is only one of them. Hope this helps.
    ----------------------------------

  6. #6
    Join Date
    Feb 2003
    Posts
    28
    ribeyed, look at my form at www.faxfoodorder.com/newpage2.asp and tell me if you still think the same way.

    name, email address, phone, pickup/delivery (dropdown box), times for pickup or delivery (dropdown box), address and company name are thew fields that I need to redisplay, after submitting to send email page.

  7. #7
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    sure yes it would work you can even populate the select boxes as well.
    ----------------------------------

  8. #8
    Join Date
    Feb 2003
    Posts
    28
    ribeyed, I finally got it to work. One problem was the Method="Get", it should have been Method="Post". I will have a lot of work making changes for the time (about 44 options), but I'll get it done.

    Now, I have one last problem. If I click on refresh, I get the following:

    "The page cannot be refreshed without resending the information".

    If I click on "retry", it submits it again. How can I make it so it refreshes or does nothing when I click on refresh?

    Thanks,

    Larry

  9. #9
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    sorry for misstake with method.


    "The page cannot be refreshed without resending the information".
    This is correct. If you click the refresh basically your telling the browers to redisplay the page the way it was when you first requested it. As the page is ASP then to do this it has to resend the information back to the server.


    How can I make it so it refreshes or does nothing when I click on refresh?
    You can't with ASP. Not sure if you can use Javascript to disable the refresh btton, but this is not recommended.
    ----------------------------------

  10. #10
    Join Date
    Feb 2003
    Posts
    28
    One last thing!

    Ribeyed, I am using dropdown box code as follows:



    <Select Name="pudeliv">

    <option name="--choose one--" value="--choose one--"

    <% if select_opt = "--choose one--" then %> <%= selected %>

    <% end if %>>

    --choose one--</option>

    <option name="Pickup" value="Pickup"

    <% if select_opt = "Pickup" then %> <%= selected %>

    <% end if %>>

    Pickup</option>

    <option name="Delivery" value="Delivery"

    <% if select_opt = "Delivery" then %> <%= selected %>

    <% end if %>>

    Delivery</option>

    </select>



    I also call the validate routine to hold values just prior to a submit to the same page as follows:



    <%

    validate = request.form("validate")

    if validate = "yes" then

    UserName = request.form("UserName")

    emailaddress = request.form("emailaddress")

    pudeliv = request.form("pudeliv")

    phone = request.form("phone")

    addressdeliv = request.form("addressdeliv")

    coname = request.form("coname")



    then I use cdonts to email me the form……

    end if

    %>



    All works fine except that when my page links to itself and returns, the pudeliv dropdown field returns to -choose one- regardless of which item I select. The email I get is fine with the proper selection.



    1. Do I need to save the pudeliv field? If so, am I doing it correctly above?

    2. What else do I need to do keep the value I selected when I come back from the link to myself?



    Thanks for taking the time, really appreciated.



    Larry

  11. #11
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    i am not sure which order you have your select box and your validation script but i will persume it is in the same order as what you have posted. If this is the case then you need to request the value of the select box before you try use the value in your if statment in your options. Bellow is an example:

    Code:
    <%pudeliv = request.form("pudeliv")%>
    
    <form action="selecttest.asp" method="post">
      <Select Name="pudeliv"> 
    
    <option name="--choose one--" value="choose one" <% if pudeliv = "choose one" then response.write "selected" end if%>>--choose one--</option> 
    <option name="Pickup" value="Pickup" <% if pudeliv = "Pickup" then response.write "selected" end if %>>Pickup</option> 
    <option name="Delivery" value="Delivery" <% if pudeliv = "Delivery" then response.write "selected" end if %>>Delivery</option> 
    
    </select>
      <input type="submit" name="Submit" value="Submit">
      
    </form>
    What you need is the request.form stuff and validation at the top of your page then your form. This way if the page is being displayed for the first time the validation part will be skipped and only display the form with the initial state for text and select boxes etc. On submit the page starts again this time it will do the validate, set values to variables for all your form elements then display the form again, but this time you have all your values to work with. You can now use them to set the submitted values on your form.

    Hope this helps.
    ----------------------------------

  12. #12
    Join Date
    Feb 2003
    Posts
    28

    Cool

    Ribeyed, It worked like a charm.

    I am very greatful for your help!

    Larry

  13. #13
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    good stuff, well done and no problem any time.
    ----------------------------------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles