Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Node.js 11 81
Power Action 2 46
Horizontal Full Calendar using php 5 42
Code planning methods/tools? 5 56
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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…

734 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