dink87522 Posted December 21, 2010 Share Posted December 21, 2010 Okay, so I have a page with a heap of fields and buttons on it (and want to keep it like that really) inside one form. Layout Box 1 Button 1 Box 2 Button 2 Box 3 Button 3 Box 4 Button 4 etc... Box 1 is called 'amount1$id' Box 2 is called 'amount.$id' where $id is the $id of the data being displayed etc So a sample form may look like Box: "amount22" Button: "Pay22" Box: "amount25" Button: "Pay25" Box: "amount32" Button: "Pay32" Box: "amount39" Button: "Pay39" Box: "amount420" Button: "Pay420" Its working fine up to that point. My problem now is that I can't work out how to get that id number from the form once submitted. If I could get the button name somehow I could do it, although I don't know the button or box names when writing the processing script. I could use a loop and check if button1 to buttonX was posted etc, although if there is a large number of entries in the database, then that starts to become a problem. Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2010 Share Posted December 21, 2010 You need to use HTML array(s) for your various form fields - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays You can then simply loop through the array data using php array functions, such as foreach(){} Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149713 Share on other sites More sharing options...
Andy-H Posted December 21, 2010 Share Posted December 21, 2010 if ( !empty($_POST) ) { $posted = array_keys($_POST); //do some shit } array_keys Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149714 Share on other sites More sharing options...
dink87522 Posted December 21, 2010 Author Share Posted December 21, 2010 I still don't really get it I don't think. I don't know what the id numbers will be though. Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149716 Share on other sites More sharing options...
Andy-H Posted December 21, 2010 Share Posted December 21, 2010 If you only need the id numbers use PFMaBiSmAd's suggestion. Follow the link he posted and be enlightened. Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149719 Share on other sites More sharing options...
dink87522 Posted December 21, 2010 Author Share Posted December 21, 2010 Okay, I don't get it. My form now looks like <input type='submit' name='Pay[60]' id='Pay[60]' value='Pay' /> <input type='submit' name='Pay[60]' id='Pay[89]' value='Pay' /> <input type='submit' name='Pay[60]' id='Pay[95]' value='Pay' /> etc My processing form part look like: $ID = strip_tags($_POST['Pay']); $ID = mysql_real_escape_string($ID); $ID is coming through as an array although I can't get/find the array contents (using print_r only gives "Array"). I even tries $ID[0] and $ID[1' etc although had no luck. What am I doing wrong??? Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149863 Share on other sites More sharing options...
dink87522 Posted December 21, 2010 Author Share Posted December 21, 2010 ? Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149885 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2010 Share Posted December 21, 2010 Using strip_tags() on an array produces an error and returns nothing. Are you developing and debugging your code on a system with error_reporting set to E_ALL (or a -1) and display_errors set to ON so that all the php detected errors in your code will be reported and displayed? You will save a TON of time. Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1149892 Share on other sites More sharing options...
dink87522 Posted December 22, 2010 Author Share Posted December 22, 2010 I removed the strip tags etc although no go still. Okay, is there another tutorial/example of thsi somewhere (the PHP official site is often hard to understand I think) as I just can't get it working. Or is there another method I could do this? Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1150227 Share on other sites More sharing options...
PFMaBiSmAd Posted December 22, 2010 Share Posted December 22, 2010 The 'code' you posted in reply #5 works after you remove the error producing strip_tags() from it (also, since $_POST['Pay'] is an array, using mysql_real_escape_string on it produces an error and returns nothing that the suggested php error_reporting/display_errors settings would help you find.) In your last tread, where you were trying to access sequentially numbered form fields, someone suggested displaying the $_POST array so that you can see what you are actually receiving. I recommend you do the same in this thread. You haven't exactly defined what you are trying to do (little or no real code), so it is not exactly possible to help you with it. What you posted in reply #5 produces an array $_POST['Pay'] that contains - Array ( [60] => Pay ) that has a key that you used in the form name and a value 'Pay'. Quote Link to comment https://forums.phpfreaks.com/topic/222258-need-some-help-with-dynamic-form/#findComment-1150243 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.