FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Get checkboxes values trough $_POST. HTML wrong?

 


devroom
Hi

Php dont get the values from the checkboxes. It does not matter how much checkboxes I check, so I think some html code is wrong.

Here is a cutout of the html code:
Code:

<form action="index.php?option=com_jms&amp;hidemenu=1&amp;func=outbox&amp;Itemid=51" method="post" name="adminForm">
..............
<tr class="sectiontableentry1 jms-readed">
     <td width="7px">1</td>
     <td width="9px"><input type="checkbox" id="cb0" name="mid[]" value="5" onclick="isChecked(this.checked);" /></td>
     <td width="30%"><a href="index.php?option=com_jms&amp;func=read&amp;id=5&amp;Itemid=51">To: test2</a></td>
     <td><div class="jms-submsg"><a href="index.php?option=com_jms&amp;func=read&amp;id=5&amp;Itemid=51">test - sdgdfgdgdfg</a></div></td>
     <td width="125px" align="right"><a href="index.php?option=com_jms&amp;func=read&amp;id=5&amp;Itemid=51">25-11-2006 19:07</a></td>
    </tr>
    <tr class="sectiontableentry2 jms-readed">
     ..........
     <td width="9px"><input type="checkbox" id="cb1" name="mid[]" value="3" onclick="isChecked(this.checked);" /></td>
     ...........
    </tr>
    <tr class="sectiontableentry1 jms-readed">
     ..........
     <td width="9px"><input type="checkbox" id="cb2" name="mid[]" value="1" onclick="isChecked(this.checked);" /></td>
     ............
    </tr>
............
</form>


PHP-Code to get the values:
Code:
$_POST['mid']
chris20
in your html, shouldn't name="mid[]" be changed to name="mid" ?
Mosquito.Tyler
chris20 wrote:
in your html, shouldn't name="mid[]" be changed to name="mid" ?


yes, and I think every check box needs a different name to work correctly.
devroom
It has to become an array, and you dont know how many checkboxes there are. So different names are needed i believe
Aredon
Just a proof of theory that the checkboxes can have the same name:
Code:

<form action="index.php?option=com_jms&amp;hidemenu=1&amp;func=outbox&amp;Itemid=51" method="post" name="adminForm">
<input type="checkbox" id="cb0" name="mid[]" value="5">
<input type="checkbox" id="cb1" name="mid[]" value="3">
<input type="checkbox" id="cb2" name="mid[]" value="1">
<input name="sb" value="submit" type="submit">
</form>
<?php
if($_POST{sb}){
$myArray=print_r(array('$_POST'=>$_POST,'$_GET'=>$_GET),TRUE);
$myArray=preg_replace('/\[mid\] => Array\s+\([^)]*\)/msU', "<span style=\"color:blue;\">$0</span>", $myArray);
echo "
<hr><pre>
$myArray
</pre>
";
}
?>


Devroom, your (X)HTML looks fine. Double check your PHP.


Last edited by Aredon on Wed Dec 06, 2006 10:32 pm; edited 1 time in total
devroom
I just fixed it Very Happy . The $_post has been moved.
Anyway i do not know why it works now. But all thx for your help Very Happy
Daniel15
Quote:
in your html, shouldn't name="mid[]" be changed to name="mid" ?

Nope, it's a POST array Wink

You can retrieve the values like so:
Code:

<?php
foreach ($_POST['mid'] as $index => $value)
    echo $value . 'was selected!<br />';
?>

(obviously, the end code would have proper data validation. Also, my code may be wrong, but it should give you the general idea)
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.