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

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.