Hi All,
I've been struggling with this problem for some time and have yet to reach a successful conclusion despite much help. I'm going to post this in HTML, Javascript, and PH forums in hope that SOMEBODY might be able to solve it.
The Objective
To have a number of identically named checkboxes on a page, that indicate an interest in a particular summer camp. The user can check more than one, but must check at least one. The checkbox is validated by a piece of Javascript on a submit button to ensure at least one is checked. The data is then processed by a PHP script which sends an e-mail.
The Problem
I cannot get both the Javascript AND the PHP to work. I can either one, but not both.
The HTML
<INPUT TYPE="checkbox" NAME="Camps" VALUE="Camp A">
<INPUT TYPE="checkbox" NAME="Camps" VALUE="Camp B">
or
<INPUT TYPE="checkbox" NAME="Camps[]" VALUE="Camp A">
<INPUT TYPE="checkbox" NAME="Camps[]" VALUE="Camp B">
The Javascript
Campswitch = 0
for (i=0; i<regform.Camps.length;i++)
{ if (regform.Camps.checked)
{ Campswitch = 1
}
}
if (Campswitch == 0)
{ alert("Please select one or more Camps and dates that you are interested in"
return false
}
The PHP
$Camps = $HTTP_POST_VARS["Camps"]);
or
$Camps = implode(",", $HTTP_POST_VARS["Camps"]);
What Happens?
If in the HTML I leave out the square brackets and in the PHP leave out the implode, the Javascript works fine and validates the form correctly, but the PHP script only returns the last value of the checkbox. If I add the square brackets and the implode, the PHP happily passes all values to the email, but the Javascript stops working.
I've messed about with this trying as many different combinations as I can think of, but just can't seem to get it to work how I want. I am so fed up with it, I'm considering allowing no boxes to be checked. Unless anybody has any ideas of what I'm doing wrong.
Grateful thanks in anticipation.
Marc
I've been struggling with this problem for some time and have yet to reach a successful conclusion despite much help. I'm going to post this in HTML, Javascript, and PH forums in hope that SOMEBODY might be able to solve it.
The Objective
To have a number of identically named checkboxes on a page, that indicate an interest in a particular summer camp. The user can check more than one, but must check at least one. The checkbox is validated by a piece of Javascript on a submit button to ensure at least one is checked. The data is then processed by a PHP script which sends an e-mail.
The Problem
I cannot get both the Javascript AND the PHP to work. I can either one, but not both.
The HTML
<INPUT TYPE="checkbox" NAME="Camps" VALUE="Camp A">
<INPUT TYPE="checkbox" NAME="Camps" VALUE="Camp B">
or
<INPUT TYPE="checkbox" NAME="Camps[]" VALUE="Camp A">
<INPUT TYPE="checkbox" NAME="Camps[]" VALUE="Camp B">
The Javascript
Campswitch = 0
for (i=0; i<regform.Camps.length;i++)
{ if (regform.Camps.checked)
{ Campswitch = 1
}
}
if (Campswitch == 0)
{ alert("Please select one or more Camps and dates that you are interested in"
return false
}
The PHP
$Camps = $HTTP_POST_VARS["Camps"]);
or
$Camps = implode(",", $HTTP_POST_VARS["Camps"]);
What Happens?
If in the HTML I leave out the square brackets and in the PHP leave out the implode, the Javascript works fine and validates the form correctly, but the PHP script only returns the last value of the checkbox. If I add the square brackets and the implode, the PHP happily passes all values to the email, but the Javascript stops working.
I've messed about with this trying as many different combinations as I can think of, but just can't seem to get it to work how I want. I am so fed up with it, I'm considering allowing no boxes to be checked. Unless anybody has any ideas of what I'm doing wrong.
Grateful thanks in anticipation.
Marc