Forum Moderators: coopster
My problem is that if the user has 1 checkbox selected and he deselects that checkbox, the form is submitted with no data, thus I have no post or get data and so I cannot find out if the form was submitted or not (Making it so that the user will never be able to deselect all the boxes and 1 will always be selected).
Is there any way around this other than putting a hidden field on the form and checking for that hidden field on $_REQUEST to find out if the form was submitted or not? Is that even a nice solution?
Best Regards
NooK
<?
/*
assuming you have field names "name" and "password" in your form
and you're using POST
*/
if(isset($_POST['name']) && isset($_POST['password'])){
/*
form is submitted -> continue validating and processing data
*/
}
else{
/* display form */
}
the field that i find that doest work in this matter is the <textarea> field type. in this case, you may want to consider alternatives such as checking the POST field for your submit button.
I haven't tested it. I would imagine that if someone entered the page for the first time that the method would be GET even if there's no query string. The other thing you could do is separate the display script from the processing script - if your form appears on page1.php,
<form action="page2.php" method="post">
then page2.php can always assume that it's responding to a POST.
In response to d40sithui, checkboxes that are not checked are not included in the POST/GET (Which I always found dumb myself, since the fact that it is unchecked doesn't mean it was not changed by the user) thus if your form consists of only checkboxes and none of the are checked and you use not submit button (Submit by javascript) your POST/GET will contain no data.
Thanks cameraman. I am not a fan of splitting up the files in 2 files but I'll give the other suggested method a try.
Best Regards
NooK
As for a submit button, it is something I didn't wnat because it is sort of a filter for a table (As soon as the user click on a checkbox to add/remove a filter the filter should be applied rather than having to click a submit button).
Thanks for the answers, I'll see what I can come up with.
Best Regards
NooK