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. Quote Link to comment 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 Quote Link to comment 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. From a usability standpoint... I'm not sure I would want to fill out a form with 1300 checkboxes Totally agree Quote Link to comment 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"; } } Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.