Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-16
3
Medium Priority
?
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

722 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