Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Sticky Forms with PHP

David Carr

Tutorials HTML PHP & MySQL

Ever submitted a form and not filled in all the field only to have to fill them all in again? This tutorial shows you how to keep your in-putted data.

To keep the in-putted data in a input field have the value call the php variable for it like this: 

value="<?php echo $name;?>"

Here is a simple form with sticky input:

<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
Name:<input type="text" name="name" value="<?php echo $name;?>"/>
<input type="submit" name="submit" value="submit" />
</form>

If something goes wrong and the form reloads the in-putted name will still be there.

To keep in-putted data in textfields you need to have the code layout slightly different like this:

<textarea name="text"><?php echo $text;?></textarea>

This will keep the text that's inputted into the textarea. 

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.