n1concepts Posted May 2, 2011 Share Posted May 2, 2011 Does anyone have suggestions on how the following can be accomplished? Objective: I need a method to grab the {$email} variable from from via $_GET and populate (display) that variable string in the textbox of the form. Example: http://[email protected] <form action='index.php' method='post' name='emailForm' id="emailForm"> <div><input type='text' name='email' id="emailBox" size="40" value='<?php echo $_POST[email]; ?>' /></div> <div><input type='submit' name='frm2' class="button2" value='submit'/> Right now, the email (captured string) variable will show once the form is submitted (based on the "POST" function but i want to be able to capture and immediately insert the email address - if provided in the top URL on initial load. Is there a way to accomplish this with PHP or do I need JavaScript? Link to comment https://forums.phpfreaks.com/topic/235386-prepopulate-text-field-in-form/ Share on other sites More sharing options...
n1concepts Posted May 2, 2011 Author Share Posted May 2, 2011 I think I can accomplish this if I pass variable into a session then call that session variable right? Link to comment https://forums.phpfreaks.com/topic/235386-prepopulate-text-field-in-form/#findComment-1209681 Share on other sites More sharing options...
Pikachu2000 Posted May 2, 2011 Share Posted May 2, 2011 You just need to add logic to determine which value to use under which condition, such as this. if( !empty($_POST['email']) ) { $email = $_POST['email']; } elseif ( !empty($_GET['email']) ) { $email = $_GET['email']; } else { $email = ''; } Link to comment https://forums.phpfreaks.com/topic/235386-prepopulate-text-field-in-form/#findComment-1209682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.