Jump to content

Post Array - Form Data


stig1

Recommended Posts

I have a form with lots of fields.

 

How would I run a loop to get each field name and data into an array, so i can then send it off to a function to process each field name / data differently. Instead of typing all the variables in the main function name for each post.

 

Would a foreach statement work?

Link to comment
Share on other sites

Your form data is already in an array, either $_POST or $_GET, depending on the form's method="" attribute.

 

You should however have a master array that contains a list of the expected field names so that you can iterate over the expected fields and detect/ignore any that a bot script or hacker is attempting to send that are not part of your actual form.

Link to comment
Share on other sites

the $_REQUEST array will contain passed $_POST and $_GET data regardless of the method declaration.

 

as to protection, use a challenge-response mechanism protection (like captcha/reCaptcha) to prevent automation through your forms. I do not recommend session tickets in hidden form values because they can be bypassed automatically by parsing the html for the hidden values.

 

 

Link to comment
Share on other sites

I guess you could use that foreach() loop to do that, but it would be identical to assigning it directly, like $kv = $_POST. What would be the point in looping through one array ($_POST) simply to assign its values to another identical array, when you can just use them directly?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.