form submission

gesf

Active 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
your.target.page?product1=value
The same checkbox, but not checked would give
your.target.page

to get the $_POST-variables right, do something like this:
Code:
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!
Code:
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':
Code:
<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;
  }
  else{
     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"
</script>
Now in the next page when you verify some var, you can see if its checkbox was checked or not making, example:
Code:
<?
$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!

And?

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

<?php
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?
 
Back
Top