Passing data from URL into a simple PHP form

software development

#1

I’m brand new to PHP (and I hope I’m in the right direction) but I’ve been searching the Internet trying to find a solution to my very simple issue.

I have a webpage (straight HTML) that has a series of links on it. On some of them I have them linked to MP3 files, but on others I want to have them linked to another page that includes a request form. The links on the latter would link to something like

==> http://www.mydomain.com/request_form?ReqDate=2008_02_01;ReqType=1.

What I then want is the second page to have a standard email form that pre-populates two of the fields in the form that they can then fill in their name and email and press submit.

The first page is easy (I think), but what I can’t seem to do is get the second page to read the variables. I thought I could do that with some statement using the ReqDate=$_GET(‘ReqDate’), but I can’t seem to get anything to do it.

I admit, that I know nothing about PHP or passing these variables so if someone can point me to some simple example of this, or even show me how to do it here, I’d REALLY appreciate it!

Murray Lahn


#2

ReqDate=$_GET('ReqDate')Are you actually using that particular statement in your code? If so, then it’s definitely not going to work, as you’re probably going to be looking at a bunch of syntax errors along the way. Did you really mean:

$ReqDate=$_GET['ReqDate']As to what you’re doing, it should be simple enough to echo the values into the form on the second page so that when the user submits the form, all of the variables get sent back to whatever script processes the form data. A very simple example might look something like this:

[code]

Name:

Email:

[/code]Notice in the example that the Req information that you came to the form page with is simply being passed through to whatever form handler script you will eventually use to process this form; if you need to do more complex things with the data, obviously, you can. This example also doesn't sanitize any of the user data, which is something you will definitely want to do in any real application.

I hope this at least helps get you moving in the right direction. :slight_smile:


#3

Thanks so much for your response. While it didn’t get me fully resolved, it did give me some insights.

I’ve taken your example and tried to integrate it into my page, however I’m still experiencing a problem. The coding I have on my page (or at least the FORM section) looks as follows…

[code]

Please fill out the following information and press "Submit"
Full Name:
Email Address:
Service Date:
Requested MP3's: The Complete Service
The Scripture and Sermon Only
Choir Anthem(s)
Praise Times(s)
Communion Praise
Other (Please specify below)


[/code]The problem is that when I call the page using [url=http://www.gscc.ca/mp3_request.htm?ServiceDate=2008_02_17]http://www.gscc.ca/mp3_request.htm?ServiceDate=2008_02_17[/url] the field ServiceDate ends up with contents of [b]"<?php echo $_GET['ServiceDate'] ?>"[/b] instead of the actual data, [b]"2008_02_17"[/b].

Do you have any idea why this might be happening?

Thanks again for your help.

Murray Lahn


#4

[quote]The problem is that when I call the page using http://www.gscc.ca/mp3_request.htm?ServiceDate=2008_02_17 the field ServiceDate ends up with contents of “<?php echo $_GET['ServiceDate'] ?>” instead of the actual data, “2008_02_17”.

Do you have any idea why this might be happening?
[/quote]
The problem is with the name you’ve given to your script. mp3_request.htm has a .htm extension, so Dreamhost is serving it up as plain HTML rather than executing it as a PHP script. If you change its name to mp3_request.php then Dreamhost will run it as a PHP script and you should see the actual data.


#5

Duh!!! I knew that! Just testing :blush:

Now to work on my default checkboxes!!

Thanks for your help!!!

Murray Lahn