Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jQuery to add form fields and PHP Sessions to remember the fields were added

I am creating a multi-paged form and now i am consulting the Stack guru's for some assistance;

On this page the user can add more input fields [type=text] onto the page

So basically there is a singular input for "CHILD NAME" then a Add button to allow the user to add more children if they have more than one.

My form allows you to go backwards and forwards, the form remembers what was input, how would i get jQuery and php to remember that the form fields were added so they are not hidden when the user re-vists the page ?

like image 693
Xavier Avatar asked Feb 01 '26 07:02

Xavier


1 Answers

well with adding inputs you can do:

$('form').append('<input>',{type: 'text', name: 'input_name'})

and you can save previous parts of the form data with php $_SESSIONs

example of a form:

in php you will get all the post (or get) values:

$_POST = array ('name1' => 'me', 'name2' => 'you' )...

and then you can save those in a session with:

$_SESSION['lastpostedvalues'] = $_POST;

or something like that.

remember to have session_start() at the top of the php file

like image 169
Naftali Avatar answered Feb 03 '26 22:02

Naftali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!