Passing Form Values to a second page when using MM Insert or Edit

This tutorial goes over all the steps to fix the Macromedia Insert or Update record coding so that the submit button will automatically pass the values of the form through the Redirect and make them available on a second page.

Pass Form Values to second page when using Macromedia's Insert Record or Update Record.

Overview: This tutorial will go over all the steps to fix the Macromedia Insert or Update record coding so that the submit button will automatically pass the values of the page through the Redirect to a second page.

This is an often asked question on the Macromedia.UltraDev Newsgroup. When using the MM Insert or update. The form is submitted back to itself, then redirected to the second page. Thus, the form values entered in page 1 are not available in page 2. I knew it was possible to automatically attach the form values back to the redirect URL and originally planned on doing an extension. However, when I got looking at MM coding a little closer, I realized that the stock MM code is supposed to do this. They just made a small mistake and used the wrong expression to get the values.

Step 1: Create your Insert Record or Edit Record using Macromedias code in the normal manner. Enter your "page2" as the redirect page.

Now, open up your code view, and find the following code. This code is the same in every MM Insert or Update Record function:

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

The code in Red is the problem code we will be changing. MM tries to pass the form elements to the next page by automatically attaching them to the redirect URL, however, Request.QueryString is the code that pulls everything from the URL after the ? in a form GET. MM uses a form POST so the Request.QueryString is empty. To get the value of everything after the ? in a form POST. We need to use a Request.Form.

Step 2: Replace all of the Red Code above, with Request.Form as shown below.

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.Form <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.Form <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.Form
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.Form
End If
End If

Step 3: All of your form values are now available to you on page 2 using
<% = Request.QueryString("yourvalue") %>
Note: this method passes all of the values in an un-encryped query string. All of the values of the form will be visible to the user in the URL.

That's it, if you have any questions, please email me at mike@jdmlt.com

 

 

Comments

Possing the parameters

February 25, 2001 by George Petrov
Mike, I don't think MM made a mistake. They just passed the parameters from the form page to the next page. Usually you don't want to pass the form fields - you store them in the db or do some actions with them.

RE: Possing the parameters

February 25, 2001 by Mike T

You are 100% right.  That is what really confused me.  I originally was planning on creating an extension that Added some code if you wanted to pass the values.  However,  everytime I added code,  it got changed somewhere else,  so I took a closer look at the stock code,   and saw the MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
that is part of the Stock code.   What is that code in the MM code for unless they were trying to add the values back into the redirect?   Then,  the second question is:  If that code is there,  why arent the values available on the redirect page?

Only answer I could come up with is,   request.querystring pulls values from a GET method.   The Insert and Update both use POST,  and you have to use the Request.Form to retrieve the values in a POST.

I am still a little confused on why the stock code is set up like it is,  but,  if anyone wants to pass values,   this will show them how to do it if they want.

Thanks
Mike T

RE: RE: Possing the parameters

February 25, 2001 by George Petrov

Well I will explain a bit. Lets take the follwoin scenario:

You have articles. On the list with all the articles you have, per article, link to the detail page. The link is something like showDetail.asp?ArtId=10

On the detail page you have a Update Record behavior. When you submit the form, it gets updated in the db, to resubmit you want:

  • redirect to "thank you" page, where you mind what to show the updated article again, so the ArtId parameter is still needed
  • redirect to "Send Notification Mail" page where you want to send a notification mail to somebody that the article has been updated. Then you also need the ArtId on the next page.

Those are just some of the examples I can think of.

Anyway - your tutorial is great! Keep up the good work!

Passing parameters

September 21, 2001 by Frédéric Frédéric

I still don't get it:

# when using the ultradev system to insert or update a record it uses a post method.  So we should request using request.form... in the reply-page.

# if we do this:  it doesn't work.

# but if we change the code in the initial page from "request.querystring" to "request.form" (as said in the tutorial) AND use "request.querysting" on the reply-page it works.

# Seems completely UNLOGIG to me.  If someone could explain it would be great!

See all 17 Comments

You must me logged in to write a comment.