Solved

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

Posted on 2010-08-16
3
434 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now