Web Hosting Forums

Results 1 to 7 of 7

This is a discussion on Processing Multiple Radio Buttons in the Hosting Talk & Chit-chat forum
Hi, I'm trying to process a form that produces, for example, a $_POST array like this: Code: Array ( [TYPE] => Array ( [0] => ...

  1. #1
    Loyal Client
    Join Date
    Feb 2002
    Posts
    144

    Processing Multiple Radio Buttons

    Hi,

    I'm trying to process a form that produces, for example, a $_POST array like this:
    Code:
    Array
    (
        [TYPE] => Array
            (
                [0] => WATER
                [1] => GAS
                [2] => COMMERCIAL
            )
    
        [a_STATUS] => Array
            (
                [0] => DONE
            )
    
        [RCVD] => Array
            (
                [0] => 2006-04-02
                [1] => 2006-02-14
                [2] => 2006-03-08
            )
    
        [DUE] => Array
            (
                [0] => OCT
                [1] => OCT
                [2] => OCT
            )
    
        [FIN_DATE] => Array
            (
                [0] => 2006-05-30
                [1] => 2006-06-08
                [2] => 2006-06-07
            )
    
        [CITY] => Array
            (
                [0] => FAIRVIEW
                [1] => GEORGETOWN
                [2] => TRENTON
            )
    
        [STATE] => Array
            (
                [0] => DC
                [1] => AR
                [2] => NJ
            )
    
       [id] => Array
            (
                [0] => 283
                [1] => 259
                [2] => 246
            )
    
        [b_STATUS] => Array
            (
                [0] => DONE
            )
    
        [c_STATUS] => Array
            (
                [0] => ACTIVE
            )
    
        [edit] => EDIT
    )
    The [a_STATUS], [b_STATUS], [c_STATUS] arrays come from fields using radio boxes with values of either DONE or ACTIVE. The number of records being edited is variable (though never more than 20), in this case it was 3. The name of this field is actually STATUS, but in order to to allow multiple pairs of radio buttons (one pair for each record) on the same form, I needed to rename them dynamically, so I appended a letter and underscore.
    Before I can process the form though, I need to modify the $_POST array to this:
    Code:
    Array
    (
        [TYPE] => Array
            (
                [0] => WATER
                [1] => GAS
                [2] => COMMERCIAL
            )
    
        [STATUS] => Array
            (
                [0] => DONE
                [1] => DONE
                [2] => ACTIVE
            )
    
        [RCVD] => Array
            (
                [0] => 2006-04-02
                [1] => 2006-02-14
                [2] => 2006-03-08
            )
    
        [DUE] => Array
            (
                [0] => OCT
                [1] => OCT
                [2] => OCT
            )
    
        [FIN_DATE] => Array
            (
                [0] => 2006-05-30
                [1] => 2006-06-08
                [2] => 2006-06-07
            )
    
        [CITY] => Array
            (
                [0] => FAIRVIEW
                [1] => GEORGETOWN
                [2] => TRENTON
            )
    
        [STATE] => Array
            (
                [0] => DC
                [1] => AR
                [2] => NJ
            )
    
       [id] => Array
            (
                [0] => 283
                [1] => 259
                [2] => 246
            )
    
        [edit] => EDIT
    )
    The only difference is the three arrays [a_STATUS], [b_STATUS], [c_STATUS] become a single array, [STATUS], containing the values of the first three, then the first three are removed from the $_POST array. I'd think I need something like:
    PHP Code:
    foreach ($_POST as $varname => $varvalue
    {
    if(
    substr($varname26) == 'STATUS')
      {
        
    //this should let me grab the appended variables, but then how to achieve the above tasks??
      
    }

    Anyone like to have a go at this?
    Last edited by soundser; 06-08-2006 at 06:29 AM.

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Could you please provide a sample of your form (either by posting a URL to a page containing the form or as a post of the relivant HTML). After looking at your form I'll probably be able to suggest changes so that you can get the results you want without having to modify things after-the-fact.

    To answer your specific question, however, you can remove values from the array with unset(). If you pass a variable to unset(), PHP removes that variable from memory (i.e. unset($fubar)). You can also pass a specific array key to unset just that portion of the array: unset($_POST['a_STATUS']).

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Loyal Client
    Join Date
    Feb 2002
    Posts
    144
    Quote Originally Posted by jason
    Could you please provide a sample of your form (either by posting a URL to a page containing the form or as a post of the relivant HTML). After looking at your form I'll probably be able to suggest changes so that you can get the results you want without having to modify things after-the-fact.

    To answer your specific question, however, you can remove values from the array with unset(). If you pass a variable to unset(), PHP removes that variable from memory (i.e. unset($fubar)). You can also pass a specific array key to unset just that portion of the array: unset($_POST['a_STATUS']).

    --Jason
    If I give you the URL, you would need to log in to my application, then complete a few steps which would require explaination (select a region, use a filter mechanism, select records to edit, etc) to get to the form in question. So I'll post the html instead. This is the form for editing 2 records. Sorry about the length.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head>
    <title>Untitled</title>
    </head>
    
    <body>
    
    <h4 class="nav2" align="center">Edit Records in Plymouth</h4><form action="/usr/edit_records.php" method="post">
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#666699"><b><font color="#FFFFFF">CLERICAL</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="405" height="1" alt="" /></th>
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>REF_NO</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>KASI_NO</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>TYPE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FORM</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CONTRACTOR</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CLIENT</b></th></tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr>
    <td><input class="input2" type="text" name="REF_NO[]" value="720020" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="KASI_NO[]" value="CN-247258" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="TYPE[]" value="COMMERCIAL" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FORM[]" value="44" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CONTRACTOR[]" value="THOMPSON REALTORS" size="14" maxlength="100" />&nbsp;</td>
    
    <td><input class="input2" type="text" name="CLIENT[]" value="MICHELLE ZUCKERMAN" size="14" maxlength="100" />&nbsp;</td></tr>
    </tr>
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#666699"><b><font color="#FFFFFF">CLERICAL 2</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    </tr>
    <tr>
    <td bgcolor="#333366" colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>STATUS</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>RCVD</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>DUE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FIN_DATE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>INVOICE</b></th></tr>
    
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input type="radio" name="a_STATUS[]" value="ACTIVE" checked />ACTIVE 
          <input type="radio" name="a_STATUS[]" value="DONE" />DONE&nbsp;</td>
    <td><input class="input2" type="text" name="RCVD[]" value="2006-04-14" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="DUE[]" value="MAY" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FIN_DATE[]" value="" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="INVOICE[]" value="" size="14" maxlength="100" />&nbsp;</td></tr>
    
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#53788e"><b><font color="#FFFFFF">LOCATION</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>AREA</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CITY</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>STATE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>ADDRESS</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>MAP</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CROSS_ST</b></th></tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input class="input2" type="text" name="AREA[]" value="2-W" size="14" maxlength="100" />&nbsp;</td>
    
    <td><input class="input2" type="text" name="CITY[]" value="SALEM" size="14" maxlength="100" />&nbsp;</td>
    <td><select class="input2" name="STATE[]" size="1">
    	<option selected="selected"  value="VA">VA</option>
        <option value="AL">Alabama</option>
    	<option value="AK">Alaska</option>
    	etc...
    	<option value="WY">Wyoming</option>
    	</select></td><td><input class="input2" type="text" name="ADDRESS[]" value="866 RECTANGLE
     TERRACE" size="14" maxlength="100" />&nbsp;</td>
    
    <td><input class="input2" type="text" name="MAP[]" value="L-13" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CROSS_ST[]" value="SATELLITES
     TERRACE" size="14" maxlength="100" />&nbsp;</td></tr>
    
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#8c8c8c"><b><font color="#FFFFFF">ROAD</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>FOREMAN</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>TRAFFIC</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>PROPOSED_SIZE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>ACTUAL_SIZE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FINISH_SQ_FT</b></th></tr>
    
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input class="input2" type="text" name="FOREMAN[]" value="ETHAN L." size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="TRAFFIC[]" value="COP" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="PROPOSED_SIZE[]" value="49x65" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="ACTUAL_SIZE[]" value="16x89" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FINISH_SQ_FT[]" value="" size="14" maxlength="100" />&nbsp;</td></tr>
    	
    </table>
    
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="#333366">
    <td><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>NOTES</b></th>
    
    </tr>
    <tr bgcolor="#333366">
    <td><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr><td class="no_border" bgcolor="#FDFFFB" align="center"><input class="input2" type="text" name="NOTES[]" value="" size="100" maxlength="255" /></td></tr>
    </table>  <input class="input" type="hidden" name="id[]" value="276" />
      <input class="input" type="hidden" name="REGIONTBL[]" value="Plymouth" />
      <br /><hr /><br /><form action="/usr/edit_records.php" method="post">
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#666699"><b><font color="#FFFFFF">CLERICAL</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="405" height="1" alt="" /></th>
    
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>REF_NO</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>KASI_NO</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>TYPE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FORM</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CONTRACTOR</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CLIENT</b></th></tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr>
    
    <td><input class="input2" type="text" name="REF_NO[]" value="510693" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="KASI_NO[]" value="CN-312479" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="TYPE[]" value="GAS" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FORM[]" value="99" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CONTRACTOR[]" value="KBJ INC" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CLIENT[]" value="MIKE SHOEMAKER" size="14" maxlength="100" />&nbsp;</td></tr>
    </tr>
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#666699"><b><font color="#FFFFFF">CLERICAL 2</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    </tr>
    <tr>
    <td bgcolor="#333366" colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>STATUS</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>RCVD</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>DUE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FIN_DATE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>INVOICE</b></th></tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input type="radio" name="b_STATUS[]" value="ACTIVE" checked />ACTIVE 
          <input type="radio" name="b_STATUS[]" value="DONE" />DONE&nbsp;</td>
    <td><input class="input2" type="text" name="RCVD[]" value="2006-04-07" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="DUE[]" value="MAY" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FIN_DATE[]" value="" size="14" maxlength="100" />&nbsp;</td>
    
    <td><input class="input2" type="text" name="INVOICE[]" value="" size="14" maxlength="100" />&nbsp;</td></tr>
    
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#53788e"><b><font color="#FFFFFF">LOCATION</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>AREA</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CITY</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>STATE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>ADDRESS</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>MAP</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>CROSS_ST</b></th></tr>
    
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input class="input2" type="text" name="AREA[]" value="1-N" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CITY[]" value="TRENTON" size="14" maxlength="100" />&nbsp;</td>
    <td><select class="input2" name="STATE[]" size="1">
    	<option selected="selected"  value="NC">NC</option>
        <option value="AL">Alabama</option>
    	<option value="AK">Alaska</option>
    	etc...
    	<option value="WY">Wyoming</option>
    
    	</select></td><td><input class="input2" type="text" name="ADDRESS[]" value="7381 HERITAGE
     TERRACE" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="MAP[]" value="M-14" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="CROSS_ST[]" value="UNLUCKINESS
     TERRACE" size="14" maxlength="100" />&nbsp;</td></tr>
    
    </table>
    <table align="center" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="gui_sched_sheet" align="center" bgcolor="#8c8c8c"><b><font color="#FFFFFF">ROAD</font></b></th>
    <th class="gui" align="center" colspan="5"><img src="images/spacer.gif" width="485" height="1" alt="" /></th>
    </tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>FOREMAN</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>TRAFFIC</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>PROPOSED_SIZE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>ACTUAL_SIZE</b></th><th class="gui" align="center" bgcolor="#F1F1F1"><b>FINISH_SQ_FT</b></th></tr>
    <tr bgcolor="#333366">
    <td colspan="6"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <td><input class="input2" type="text" name="FOREMAN[]" value="BILL C." size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="TRAFFIC[]" value="" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="PROPOSED_SIZE[]" value="53x100" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="ACTUAL_SIZE[]" value="88x44" size="14" maxlength="100" />&nbsp;</td>
    <td><input class="input2" type="text" name="FINISH_SQ_FT[]" value="" size="14" maxlength="100" />&nbsp;</td></tr>
    	
    </table>
    
    <table align="center" class="gui_tight" width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="#333366">
    <td><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr>
    <th class="gui" align="center" bgcolor="#F1F1F1"><b>NOTES</b></th>
    
    </tr>
    <tr bgcolor="#333366">
    <td><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
    </tr>
    <tr><td class="no_border" bgcolor="#FDFFFB" align="center"><input class="input2" type="text" name="NOTES[]" value="ASK ABOUT BASE REALIGN" size="100" maxlength="255" /></td></tr>
    </table>  <input class="input" type="hidden" name="id[]" value="271" />
      <input class="input" type="hidden" name="REGIONTBL[]" value="Plymouth" />
    
      <br /><hr /><br /><br />
    <br />
    <div align="center">
    <input class="input" type="hidden" name="sheet" value="Plymouth" />
    <input class="input" class="button" type="submit" name="edit" value="EDIT" /> 
    </div>
    </form> 
    </table>
    
    </body>
    </html>
    re: unset
    I tried this:
    PHP Code:
    foreach ($_POST as $varname => $varvalue
    {
      if(
    substr($varname26) == 'STATUS')
      {
         unset(
    $varname,);
      }

    ...but it did not remove a_STATUS, b_STATUS, or c_STATUS.

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    I'll look over your HTML in a minute, but first...

    When you do a foreach with the "$var as $key => $value" notation as you have, what you are really doing is creating two new variables ($key and $value) that contain copies of the key and value of an element of the $var array. So when you unset($key) you are only destroying the $key variable itself, not the original. What you need to do is actually unset($var[$key]), or in your case specifically, unset($_POST[$varname]).

    I would recommend doing this in a separate loop, after you finish processing the submitted values, as removing elements from an array through which you are looping sometimes causes problems. In other words, I'd do soemthing like this:

    PHP Code:
        foreach($_POST as $varname => $varvalue) {
            if(
    substr($varname26) == 'STATUS') {
                
    //put variable into "status" array
            
    }
        }

        
    //once all of that is done
        
    foreach($_POST as $varname => $varvalue) {
            if(
    substr($varname26) == 'STATUS') {
                unset(
    $_POST[$varname]);
            }
        } 
    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    You are using radio buttons since you only want one value per status field (in other words, a_STATUS would be either "active" OR "done," but never both). However, the way you have your fields set up now, $_POST['a_STATUS'][0] may be "active" or null, and $_POST['a_STSTUS'][1] may be "done" or null.

    The easiest fix would be to use "STATUS" as the field name, but to place an index number into the brackets. So instad of using "a_STATUS[]" you should simply use "STATUS[0]" for the field name of both current a_STATUS fields and then increment the index number for each other status field (b_STATUS = 1, c_STATUS = 2, etc.). Then your submitted variables will be as you want them with no munging.

    To improve readability of your form, you may want to also add index variables to the names of the other fields (ie CLIENT[0]). This isn't required because PHP will append the values to the array automatically with just [], but adding index numbers will make it easier to understand what variables go together to someone reading/modifying/debugging your form.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  6. #6
    Loyal Client
    Join Date
    Feb 2002
    Posts
    144
    Quote Originally Posted by jason
    The easiest fix would be to use "STATUS" as the field name, but to place an index number into the brackets. So instad of using "a_STATUS[]" you should simply use "STATUS[0]" for the field name of both current a_STATUS fields and then increment the index number for each other status field (b_STATUS = 1, c_STATUS = 2, etc.). Then your submitted variables will be as you want them with no munging.

    --Jason
    Thanks very much Jason, I followed this advise and it's working great - no munging!

  7. #7
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    You're welcome.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •