Search code examples
phphtmlregistration

registration form error handling: remember correct fields


I'm writing a registration form with html/php. However, I also included a captcha, which will be verified by my php-scripts after the user has submitted the form.

In case the captcha was wrong, I don't want the user having to retype everything into the form again. How can I pre-fill the information that was already entered back into those fields?


Solution

  • Assuming that you are rendering on the post request only here is a sample code you can use

    <form>
    <input type="text" placeholder="name" value=<?php echo $_POST["name"];?>>
    // Code for captcha
    </form>
    

    Do remember to sanitize the POST according to your use case or it would lead to XSS on your form.