Jump to content

Prepopulate Text Field in form


n1concepts

Recommended Posts

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

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 = '';
}

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.