Jump to content

Count and display checkbox values


lantafly

Recommended Posts

Hello,

 

I'm having a bit of trouble counting checkbox values and displaying them properly in the form results. The form I am working with will count the values of the checkboxes and display them with their id's and/or values associated with them in the form results page. I've tried using an count() array function to accomplish this, but it only counts the total amount of checkboxes selected and doesn't calculate the checkbox values.

 

Here's an example of the results I want to achieve along with the form code and php code I am using:

 

Desired results formatting (based on checkbox selection):

 

Full Day Junior Camp: Date1 ($140.00)

Half Day Junior Camp: Date2 ($80.00)

Mini Junior Camp: Date1 ($40.00), Date2 ($40.00)

First Name:

Last Name:

Parent Name:

Address:

Phone:

Email Address:

Number of Days Selected: 4

Total Payment Amount: $300

 

-----------------------------------------------

 

Here's the form code:

 

<form name="SummerCampReg" action="SummerCampRegistration.php" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150" rowspan="2">Full Day Junior Camp</td>
    <td width="150"><input name="FullDayJuniorCamp" type="checkbox" id="June1-4" value="140.00" />
      June 1-4</td>
  </tr>
  <tr>
    <td><input name="FullDayJuniorCamp2" type="checkbox" id="June8-11" value="140.00" />
      June 8-11</td>
  </tr>
  <tr>
    <td rowspan="2">Half Day Junior Camp</td>
    <td><input name="HalfDayJuniorCamp" type="checkbox" id="June1-4" value="80.00" />
      June 1-4</td>
  </tr>
  <tr>
    <td><input name="HalfDayJuniorCamp" type="checkbox" id="June8-11" value="80.00" />
      June 8-11</td>
  </tr>
  <tr>
    <td rowspan="2">Mini Junior Camp</td>
    <td><input name="MiniJuniorCamp" type="checkbox" id="June1-4" value="40.00" />
      June 1-4</td>
  </tr>
  <tr>
    <td><input name="MiniJuniorCamp" type="checkbox" id="June8-11" value="40.00" />
      June 8-11</td>
  </tr>
  <tr>
    <td> 
    </td>
    <td> </td>
  </tr>

  <tr>
    <td> 
    </td>
    <td><input name="Submit" type="submit" value="Submit" /></td>
  </tr>
</table>

 

-----------------------------------------------

 

Here's the results page code:

 

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FullDayJuniorCamp');
pt_register('POST','HalfDayJuniorCamp');
pt_register('POST','MiniJuniorCamp');
pt_register('POST','FirstName');
pt_register('POST','LastName');
pt_register('POST','HomeAddress');
pt_register('POST','ParentGuardianName');
pt_register('POST','ParentGuardianEmail');
pt_register('POST','ParentGuardianPhone');
pt_register('POST','EmergencyPhone');
$fee = count($_POST['FullDayJuniorCamp']+$_POST['HalfDayJuniorCamp']+$_POST['MiniJuniorCamp']);
$total = $fee;
if($FullDayJuniorCamp=="" || $HalfDayJuniorCamp=="" || $MiniJuniorCamp=="" || $FirstName=="" || $LastName=="" || $HomeAddress=="" || $ParentGuardianName=="" || $ParentGuardianEmail=="" || $ParentGuardianPhone=="" ){
$errors=0;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Full Day Junior Camp: ".$FullDayJuniorCamp."
Half Day Junior Camp: ".$HalfDayJuniorCamp."
Mini Junior Camp: ".$MiniJuniorCamp."
First Name: ".$FirstName."
Last Name: ".$LastName."
Address: ".$HomeAddress."
Parent Name: ".$ParentGuardianName."
Email: ".$ParentGuardianEmail."
Phone: ".$ParentGuardianPhone."
Pay Amount: ".$total."
";
?>

 

---------------------------------------

 

I left out a few form fields on purpose and just included the meat of the form. I know my code is a bit sloppy :D, but hey...I'm a newb. Any assistance or direction would be awesome!

 

Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.