Solved

php prevent user from having to refill text field if submission error

Posted on 2010-08-16
3
435 Views
Last Modified: 2012-05-10
Hi,

If a user accidently does not fill out a php form correctly all of their information entered in the fields is erased.

How do I keep the information in the text fields if their is some kind of error with their submission?

the code below does not seem to work for me.

thanks.
<input name="emailConfirm" value="<?php echo emailConfirm;?>"/>

Open in new window

0
Comment
Question by:Solutionabc
3 Comments
 
LVL 3

Expert Comment

by:cloud-9
ID: 33451346
You need to get the post/get values when the form is submitted. This example is very basic, just pretend there are two form fields...I guess.
<?php
$name="Name";
//Processing
if(isset($_POST['name']){
  $name=$_POST['name'];
  if($name!="Name"&&preg_match('/some name regex/',$name)){
    //Preform save action
    }
  else {
    $errors="You did not enter your name.";}}
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
  <?php echo $errors ?>
  <input type="text" name="name" value="<?php echo $name ?>"/>
  <input type="submit" value="Send"/>
</form>

Open in new window

0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 250 total points
ID: 33451833
<input name="emailConfirm" value="<?php echo emailConfirm;?>"/>

Replace with this

<input name="emailConfirm" value="<?php echo $emailConfirm;?>"/>

Hope this helps
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33467159
you could use ajax to post the values to php, then if an error is returned, prompt the error and the form will remain the way it was
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question