Solved

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

Posted on 2010-08-16
3
433 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:
shinuq 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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 …

708 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

17 Experts available now in Live!

Get 1:1 Help Now