dhope Posted January 19, 2011 Share Posted January 19, 2011 Hi, Is it possible to retrieve all the information from a posted value without knowing the input field? My page is taking information from a database and then creates a page with checkboxs so that people can select certain fields. There are 1300 fields in the database so I don't know what fields will be submitted when a person saves the page, is there a simple way to check what fields have been submitted without writing a check for each checkbox? I hope this makes sense, thanks in advance for any help. Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/ Share on other sites More sharing options...
MatthewJ Posted January 19, 2011 Share Posted January 19, 2011 Checkbox data should be in an array within post. <input type='checkbox' name='checkboxes[]' value='value1' /> <input type='checkbox' name='checkboxes[]' value='value2' /> <input type='checkbox' name='checkboxes[]' value='value3' /> Then you can just loop through the $_POST['checkboxes'] array From a usability standpoint... I'm not sure I would want to fill out a form with 1300 checkboxes Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1161983 Share on other sites More sharing options...
TOA Posted January 19, 2011 Share Posted January 19, 2011 This might be what you're looking for foreach ($_POST as $key => $value) { if (isset($value)) { do something with the input } } It checks all posted values and looks to see if it's set. If it is it does something with the value. If I'm not understanding correctly, my apologies. Quote From a usability standpoint... I'm not sure I would want to fill out a form with 1300 checkboxes Totally agree Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1161986 Share on other sites More sharing options...
dhope Posted January 19, 2011 Author Share Posted January 19, 2011 The checkboxs are split up into sections making it much easier to use I have tried the examples posted but it only seems to print out the last checkbox to be selected, any ideas? CODE: if(isset($_GET['update_towns'])) { foreach ($_GET as $key => $value) { print "$value"; } } Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1162182 Share on other sites More sharing options...
TOA Posted January 19, 2011 Share Posted January 19, 2011 Well that code right there says: Only loop through the GET array if update_towns isset Is that what you want it to do? If update_towns is not set, the script will do nothing Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1162185 Share on other sites More sharing options...
dhope Posted January 19, 2011 Author Share Posted January 19, 2011 Yes, I have set a hidden field to update_towns so that I can check if the form has been submitted, i'm not sure if there is a better way of doing this. The foreach doesn't seem to loop through it just seems to print out the final checkbox that was selected. Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1162187 Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2011 Share Posted January 19, 2011 Getting an accurate answer to this without posting the code that generates the form may prove difficult. Link to comment https://forums.phpfreaks.com/topic/224975-retrieve-information-from-_post/#findComment-1162192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.