form submission


New member
When you make a search, you´ll have to fetch some data and printing that data/result whithing the checkbox code, am i right !?
Can´t you assign to the checkbox value, some data of the result to identify it ?
Actually, when a checkbox in an HTML form is left unchecked, nothing is passed on about it to the target page.

f.ex. a checkbox called "product1" which is checked, would give
The same checkbox, but not checked would give

to get the $_POST-variables right, do something like this:
while ($product = mysql_fetch_array($query)) {

'<input type="checkbox" name="'.$product[name].'" value="checked">'


hope this is of any help to you
Ohh, i see!
Let´s try it with javascript! This is just an idea on how to verify the checkbox!
Start by printing this instead of that you´ve posted. In this one we´re creating another hidden input with the name: 'hcbox_'+ fieldname!
while ($product = mysql_fetch_array($query)) { 
echo '<input type="checkbox" name="'.$product[name].'" value="checked">';
echo '<input type="hidden" name="hcbox_'.$product[name].'" value="" onChange="javascript:check_cbox(this.form,this,\'hcbox_'.$product[name].'\')">';

This is the javascript function to specify (under the hidden input), whether the checkbox is checked or not, by writing on it 'TRUE' or 'FALSE':
<script language="JavaScript">
function check_cbox(myform, mycbox, myhfield){
  if (document.myform.mycbox.checked){
     document.myform.myhfield.value = "";
     document.myform.myhfield.value = "TRUE"; 
     return true;
     document.myform.myhfield.value = "";
     document.myform.myhfield.value = "FALSE"; 
     return true;

// If you want, instead of all that above:
// hpath = document.myform.myhfield;
// if (document.myform.mycbox.checked)?hpath.value = "TRUE" : hpath.value = "FALSE"
Now in the next page when you verify some var, you can see if its checkbox was checked or not making, example:
$new_var = 'hcbox_' . $_POST['var'];
if($new_var == "TRUE"){
// Do something
else(){ // is FALSE
// Do another thing
Well, i made this in notepad and i didn´t test it. I´m almost sure it will work, of course it may have some little bugs :p Try it!
This seems like an awful lot of work for something that can be solved by a single array_key_exists() or empty()..
Hunn...i don´t think so...!
I mean...maybe empty(), but i don´t see how.
This is the same problem as here!
The problem is verifying whether the checkbox is checked or not and giving an 'action' depending on it!
gesf said:
The problem is verifying whether the checkbox is checked or not and giving an 'action' depending on it!


<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	<input type="checkbox" name="checkbox1" value="1" />
	<input type="submit" />

if(!array_key_exists('checkbox1', $_GET) || empty($_GET['checkbox1'])) {
   echo 'The checkbox is not checked!';
} else {
   echo 'The checkbox is checked and the value is ' . $_GET['checkbox1'] . '!';

The above works absolutely like a charm. What's the problem?