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://domain.com?email=john.smith@abc.com

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.