Jump to content

Dynamic form AJAX submit


freelance84

Recommended Posts

I have a rather complicated form with a combination of hidden fields, radio buttons and check boxes.

 

The quantity of form elements is decided by the user, elements are removed and added with js and jquery.

 

At present the user finalizes the content on their form and hits a submit button which send the form data in the traditional way back to the server in the $_POST array. The php processes the data and produces results accordingly.

 

Nothing too unusual there. However, the user may wish to hit the same submit button several times to generate different results: Each time the form is submitted the whole html page has to be reloaded. Whilst trying to optimize the site I have decided to eliminate this complete page refresh in favour for AJAX the only bit of data the user is interested in is only 1 tenth the entire content of the page...

 

 

So:

I found (i think it may have been from a previous post on here this: http://pietschsoft.com/post/2006/06/01/Javascript-Loop-through-all-elements-in-a-form.aspx

 

This is great, i could loop through all the elements of the form with a js function, filter accordingly, then $_POST the data with AJAX to the processor which in turn echo's the results...

 

This does however feel like there is an extra and unnecessary step. Is there a more efficient way?

 

Is there any way of simply replicating the browsers form submit with AJAX. ie simply sending the whole form in the same way that the browser does? Or am i barking up the wrong tree? Is the only way to loop through all the elements?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.