Jump to content

Links to Forms


jwasho

Recommended Posts

So I'm new to PHP, but i'm picking it up fairly quickly.  What I'm trying to do (and frankly have absolutly no idea how) is to have a page with a bunch of links and each links to the same form, but there's a field in the form for a link ID number and i want the client to be able to fill in that number themselves, OR FOR THE LINK THEY CLICKED TO AUTOMATICALLY FILL IN THE ID NUMBER.

 

 

I have a php form right now to take care of the first part, but like i said no idea how to do the automatic part.

 

thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/106568-links-to-forms/
Share on other sites

You can access variables passed via a URL using the $_GET variable.

 

If you want to automatically get an input field to take on a value, you could do something like:

echo "<input type=\"text\" value=\"", $_GET['variable1'], "\" />";

 

However, you shouldn't ever trust user input, and this data should be validated before doing something like that.

 

A possible way to validate the data (if it's numeric):

if (isset($_GET['variable1']) && is_numeric($_GET['variable1']))
{
 $myVariable = $_GET['variable1'];
}
else
{
 $myVariable = <some_default_value>;
}

/* Code to show the form field goes here */

Link to comment
https://forums.phpfreaks.com/topic/106568-links-to-forms/#findComment-546274
Share on other sites

ok so this is the code i have for the link:

 

To sign up for this course, click <a href="cpr1form.php" variable="variable1">here</a> ...

 

 

and then in the form code:

 

Course ID Number: <input name="cid" type="text" value="", $_GET[variable1] />

 

did I understand that right?

Link to comment
https://forums.phpfreaks.com/topic/106568-links-to-forms/#findComment-549363
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.