cbassett03 Posted August 9, 2013 Share Posted August 9, 2013 How can I get the names and values from an HTML form using PHP when the form is submitted using a Submit button? I think this may involve using a foreach loop (since the form will be dynamically created each time depending on other factors). But I need to be able to capture the form control's name and its value when it is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/281006-get-names-values-of-all-html-form-elements-with-php/ Share on other sites More sharing options...
kicken Posted August 9, 2013 Share Posted August 9, 2013 The $_POST/$_GET arrays will contain all the name value pairs. Which you use depends on the form's method. Just do a foreach loop over the appropriate array: foreach ($_POST as $name=>$value){ //.... } Quote Link to comment https://forums.phpfreaks.com/topic/281006-get-names-values-of-all-html-form-elements-with-php/#findComment-1444212 Share on other sites More sharing options...
Zane Posted August 9, 2013 Share Posted August 9, 2013 (edited) [ignorant response removed ] Nevermind, I read that wrong kicken has the answer. ^^^^ Edited August 9, 2013 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/281006-get-names-values-of-all-html-form-elements-with-php/#findComment-1444232 Share on other sites More sharing options...
mac_gyver Posted August 10, 2013 Share Posted August 10, 2013 i would recommend against unconditionally looping over all submitted form data (a hacker/bot can submit hundreds/thousands of pieces of data.) you should know what fields your form will submit and if you are dynamically adding fields, their names should be of a known scheme (array names) so that you know what to expect when you condition, filter, validate, and process the submitted data. Quote Link to comment https://forums.phpfreaks.com/topic/281006-get-names-values-of-all-html-form-elements-with-php/#findComment-1444265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.