Ilja
Ilja

Reputation: 46509

How to memorize data that was entered in form before it was submitted

I came across the problem, I use re-captcha to validate user input. I made it so if wrong captcha was entered it displays an error message. It works fine, but once user submits form it reloads the page to show an error message, because of this all data entered by user gets lost. Is there a way to memorize what user entered before, so the only thing they need to change is a captcha text?

Here is the page: http://inelmo.com/create_story.php submit a form with wrong captcha to see an error message and you will see that all data gets lost.

Upvotes: 0

Views: 215

Answers (3)

extols
extols

Reputation: 1772

As the form was submitted to the PHP script you already have access to all they information which they provided. It is simply a case of echoing the POST data into the markup.

Upvotes: 0

Anonymous
Anonymous

Reputation: 6251

To combat this (as well as to allow PHP-validation to work for JS disabled users) I often use:

<input type="text" id="whatever" name="whatever" value="<?= $_POST['whatever']; ?> />

This way, any submitted data will be returned. :)

Upvotes: 0

nine7ySix
nine7ySix

Reputation: 461

You can try settings the values for the inputs. So something like <input type="text" name="something" value="<?php echo $_POST['something'];?>">

Upvotes: 1

Related Questions