jwasho Posted May 21, 2008 Share Posted May 21, 2008 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 More sharing options...
p2grace Posted May 21, 2008 Share Posted May 21, 2008 The link would have a get variable at the end of it, then just grab that get variable on the form and set it on the id value. Link to comment https://forums.phpfreaks.com/topic/106568-links-to-forms/#findComment-546273 Share on other sites More sharing options...
jamesnes Posted May 21, 2008 Share Posted May 21, 2008 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 More sharing options...
jwasho Posted May 22, 2008 Author Share Posted May 22, 2008 Ok great. Thanks I'm going to try all of this and i'm sure i'll have more questions. Link to comment https://forums.phpfreaks.com/topic/106568-links-to-forms/#findComment-547044 Share on other sites More sharing options...
jwasho Posted May 25, 2008 Author Share Posted May 25, 2008 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 More sharing options...
wrathican Posted May 25, 2008 Share Posted May 25, 2008 sorry to say but that is completely wrong. there is not such 'variable' html tag Read this, it will give you a good understanding of what is going on in the post by jamesnes http://www.w3schools.com/PHP/php_get.asp Link to comment https://forums.phpfreaks.com/topic/106568-links-to-forms/#findComment-549393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.