mo Posted January 22, 2009 Share Posted January 22, 2009 I am receiving error "Fatal error: Cannot use string offset as an array in ....". I have a web form with several groups of radio buttons and checkboxes which are all dynamically created based on MySQl entries. When a user submits the form, I go through a series of checks. For checkboxes I check if a users only selected less than the max amount of boxes. All my logic workes fine when I just have one group of checkboxes but when I have multiple groups of checkboxes, I need the attributes of said group in order to determine if the group is a group of check boxes or radio buttons or if the group has a max box selection setting and if so how many boxes can be selected. To paint a clear picture in regards to the groups of boxes. Lets take a website like pizzahut and let's say we're ordering a pizza and we're presented a window with a box that has meat toppings and a box that has vegetable toppings. The system only lets you choose 2 toppings from the meat list and 3 from the vegetable list. This is similiar to my situation. I build a form dynamically and than during processing of the form I need to check for the selected boxes and and make sure not more than the max amounts were selected. Snippet of code used to build the boxes: <form ...> ... while($ArrayRow = mysql_fetch_array($sqlStr)) { ... //Build array of option attributes $OptAttrArray = array( array($strOptId,$strPrice,$strIsOption,$strBtype,$strMaxOptions) ); if($strBtype == 'RADIO'){ //Format radio buttons echo "<tr><td class=\"dataListItem\"> <input type=\"radio\" name=\"itemoption[]\" value=\"$OptAttrArray\"></td> <td class=\"dataListItem\">$strDesc</td> <td class=\"dataListItem\">$strPrice</td></tr>"; }else{ //Format checkboxes echo "<tr><td class=\"dataListItem\"><input name=\"itemoption[]\" type=\"checkbox\" value=\"$OptAttrArray\"></td> <tdclass=\"dataListItem\">$strDesc</td> <tdclass=\"dataListItem\">$strPrice</td></tr>"; }//ENDIF CHECK BUTTON TYPE }//End While blah, blah, blah..... </form> My issue I think is that I create an array (itemoption[]) for the input field which holds all the buttons on the screen. The value for each button is another array that holds the attributes ($OptAttrArray). During form processing when the user clicks submit, I do the following. foreach($_POST['itemoption'] as $val => $value) { //Seperate value sub array into attribute fields $strOptId = $value[0][0]; $strPrice = $value[0][1]; $strIsOption = $value[0][2]; $strBtype = $value[0][3]; $strMaxOptions = $value[0][4]; .... } This is where I receive the error "Fatal error: Cannot use string offset as an array in ....". Link to comment https://forums.phpfreaks.com/topic/142015-solved-array-issues-processing-forms-with-multiple-radio-button-groups/ Share on other sites More sharing options...
mo Posted January 22, 2009 Author Share Posted January 22, 2009 I resolved the issue. Link to comment https://forums.phpfreaks.com/topic/142015-solved-array-issues-processing-forms-with-multiple-radio-button-groups/#findComment-743677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.