Getting all html form data in a multi-paged/multi-part form

1.6k views Asked by At

I have a multi-paged forms and I need to get all the data from the forms. I know I can do this manually but I want a more dynamic approach. Yeah, if possible, please give me an answer using javascript only.

Edit... I'm sorry if it was somewhat vague. What I want to do is to present to the user all the data he entered, so i think this is client-side not server-side. Also, I have installed PHP now. So, if there's a PHP way, then that's also ok.

It's multi-paged because the user will jump from different web-pages because it will be very long if the user will input all the data in just one page. Hmmm... an example would be a tax-filing form. Or some kind of census. That's how long the form is and the amount of data I have to get. So, I want to know a dynamic way to do it.

I'm still not finished. Thanks to the comments below. I have tried them and some are beneficial.

3

There are 3 answers

0
Jinnean On BEST ANSWER

Ok, I think I have solved my problem. This is how I did it.

First, instead of using multiple pages, I used hidden divs and make it visible as the user clicks the next page and make the present form hidden.

Then, I learned that I can access all the data by using this code:
var value = document.forms[formname].elements[index].value;
and put it inside a loop

and then process it all by:

<?php 
if (!empty($_POST['form1'])) {
    //do some sever-side processing and validation;
}

if (!empty($_POST['form2'])) {
    //do some sever-side processing and validation;
}

.....
?>

Thanks for all the help btw.

6
clem On

with jquery's serialize you can get every field from a form and then send it to a php script with ajax

1
Grrbrr404 On

Try this

$.post("destination_site.php", $("form").serialize());

It selects all "form" Tags on the page it is executed and then post the serialized data to "destination_site.php"

On your script site, you can access them with $_POST['name_of_input_element']

If you want to access the input elements on the client site, you dont need to post them. Use this to access all input elements of all forms of your site

$.each("form :input", function(index, value) { 
  // show message box of input value
  alert($(this).val());
});