Skip to content
Advertisement

Pass form data to PHP script with jquery [closed]

I have the following form I’ve been working on.

Now, I’m unsure how to grab the form data and push it to my update.php script.

I’d like my update.php script to loop through the rows in index.php and output the account_name value for each.

JavaScript

Advertisement

Answer

As mentioned in my comment and depending on your intention behind the form submission, you would want to use the <form> to allow for jQuery to serialize() and submit the data to the specified URL.

Below I use a pseudo database result as the $accounts array, in order to output each of the accounts within your form.

I also optimized the code based on standard practices such as escaping the database values using htmlentities or htmlspecialchars being output in your HTML code, to ensure they do not break the DOM with the single or double quotes.

/index.php

JavaScript

Now you can retrieve the $_POST results in update.php.

/update.php

JavaScript

Special considerations: PHP by default has a limited amount of input values that can be requested at one time. Please update your form pagination or PHP max_input_vars and post_max_size configuration accordingly to prevent missing data.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement