Check box value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ethoemmes
Forum Commoner
Posts: 26
Joined: Thu Aug 18, 2005 4:11 pm

Check box value

Post by ethoemmes »

Hi

I am using the below code to collect users comments from my website. I have added a check box to the form which asks if the user would like to be added to the mailing list. I need help with 2 problems here.

1. The script doesn't seem to be recognising that the checkbox is checked. Is there another way to test its value?
2. How could I transfer values from the comments form to the mailing list form. For e.g. I ask for name and email address on the comments form and I would like to transfer this information to the mailing list form to save the user having to type it in again.

Code: Select all

<?php

$Title = $_POST['Title'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Email = $_POST['Email'];
$Comments = $_POST['Comments'];
$AddToML = $_POST['AddToML'];

$strMailTo = 'Edgar@rrbltd.com';
$strSubject = 'Enquiry from Website';
$strBody = "$Comments \n
Received from \n
$Title $FirstName $LastName \n
$Email
$AddToML";

$From = "From: \"$FirstName $LastName\" <$Email>\nX-Mailer: PHP/" . phpversion();

mail ($strMailTo, $strSubject, $strBody, $From);

if ($AddtoML == 'ON') {
header( "Location: http://www.rrbltd.com/Development/Regis ... rm_v1a.htm" );
}
else {
header( "Location: http://www.rrbltd.com");
}

?>
TIA
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it may help to see the form you're using. The checkbox field will only exist in the submission if it was checked..

and sessions are good for transferring the data from one form to the other.
ethoemmes
Forum Commoner
Posts: 26
Joined: Thu Aug 18, 2005 4:11 pm

Forms

Post by ethoemmes »

I have added both forms below. Could any point either get me started with sessions or point me to a good web resource?

Comment form

Code: Select all

<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<TITLE>Contact Form</TITLE>
<link href="../stylesheets/styles.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY>
<table width="90%" cellspacing="0" align="center" cellpadding="0" class="body">
  <tr>
    <td width ="20%" align="left"> <img src="../banner.gif" width="178" height="75" title="Rudi Thoemmes Rare Books" /> </td>
    <td align="center" valign="middle" class="head">Contact Form </td>
  </tr>
  <tr>
    <td align="left" valign="top"><table width="100%"  border="0" cellpadding="5" cellspacing="0" class="current">
        <tr>
          <td><a href="index.html" class="links">Index</a></td>
        </tr>
        <tr>
          <td>Current Catalogue</td>
        </tr>
        <tr>
          <td>Mailing List </td>
        </tr>
        <tr>
          <td>Company Outline </td>
        </tr>
    </table></td>
    <td align="left"><table width="100%"  border="0" cellpadding="5" cellspacing="0">
      <tr>
        <td align="center"><FORM METHOD="POST" ACTION="comment.php">
        <p class="links">Please provide the following contact information:</p>
    <TABLE border="0" cellpadding="5" cellspacing="0" class="body" height="172" width="618">
          <TR>
            <TD ALIGN="right" height="25" width="112"> Title</TD>
            <TD height="25" width="361">
              <select name="Title" id="select">
                <option value="Mr" selected>Mr</option>
                <option value="Mrs">Mrs</option>
                <option value="Ms">Ms</option>
                <option value="Miss">Miss</option>
                <option value="Doctor">Doctor</option>
                <option value="Professor">Professor</option>
              </select></TD>
          </TR>
          <TR>
            <TD ALIGN="right" height="25" width="112"> First Name<span lang="en-gb">
            </span></TD>
            <TD height="25" width="361">
              <INPUT NAME="FirstName" TYPE=TEXT class="boxborder" SIZE=17>
            </TD>
            </TR>
          <TR>
            <TD ALIGN="right" height="25" width="112"> Last Name</TD>
            <TD height="25" width="361">
              <INPUT NAME="LastName" TYPE=TEXT class="boxborder" SIZE=17>
            </TD>
            </TR>
          <TR>
            <TD ALIGN="right" height="25" width="112"> E-mail</TD>
            <TD height="25" width="361">
              <INPUT NAME="Email" TYPE=TEXT class="boxborder" SIZE=35>
            </TD>
            </TR>
          <tr>
            <TD ALIGN="right" valign="top" height="78" width="112"> <p>Enquiry
                  /<br>
                  Comments </p>              </TD>
            <TD valign="top" height="78" width="361">
              <textarea name="Comments" cols="53" rows="10" id="Comments"></textarea>
            </TD>
            </tr>
          <TR>
            <TD ALIGN="right" valign="top" height="25" width="112"> &nbsp;</TD>
            <TD valign="top" height="25" width="361">
              <input type="checkbox" name="AddToML" value="ON"><span lang="en-gb">Would
              you like to be added to our mailing list?</span></TD>
            </TR>
        </TABLE>
      </BLOCKQUOTE>
      <p>
        <INPUT name="SUBMIT" TYPE=SUBMIT VALUE="Submit Form">
        <INPUT name="RESET" TYPE=RESET VALUE="Reset Form">
        </p>
        </FORM></td>
      </tr>
    </table></td>
  </tr>
</table>
</BODY>
</HTML>
Registration form

Code: Select all

<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<TITLE>Registration Form</TITLE>
<link href="../stylesheets/styles.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY>
<table width="90%" cellspacing="0" align="center" cellpadding="0" class="body">
  <tr>
    <td width ="20%" align="left"> <img src="../banner.gif" title="Rudi Thoemmes Rare Books" /> </td>
    <td align="center" valign="middle"><span class="title">Registration Form </span></td>
  </tr>
  <tr>
    <td align="left" valign="top"><table width="100%"  border="0" cellpadding="5" cellspacing="0" class="current">
        <tr>
          <td><a href="index.html" class="links">Index</a></td>
        </tr>
        <tr>
          <td>Current Catalogue</td>
        </tr>
        <tr>
          <td>Mailing List </td>
        </tr>
        <tr>
          <td>Company Outline </td>
        </tr>
    </table></td>
    <td align="left"><table width="100%"  border="1" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td align="center"><FORM METHOD="POST" ACTION="form.php">
        <p>Please provide the following contact information:</p>
    <TABLE>
          <TR>
            <TD ALIGN="right"> Title</TD>
            <TD>
              <select name="Title" id="select">
                <option value="Mr" selected>Mr</option>
                <option value="Mrs">Mrs</option>
                <option value="Ms">Ms</option>
                <option value="Miss">Miss</option>
                <option value="Doctor">Doctor</option>
                <option value="Professor">Professor</option>
              </select></TD>
          </TR>
          <TR>
            <TD ALIGN="right"> First Name</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="FirstName" SIZE=35>
            </TD>
          </TR>
          <tr>
            <TD ALIGN="right"> Middle Name</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="MiddleName" SIZE=35>
            </TD>
          </tr>
          <TR>
            <TD ALIGN="right"> Last Name</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="LastName" SIZE=35>
            </TD>
          </TR>
          <TR>
            <TD ALIGN="right"> E-mail</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Email" SIZE=25>
            </TD>
          </TR>
          <TR>
            <TD ALIGN="right"> &nbsp;</TD>
            <TD>
              &nbsp;</TD>
          </TR>
          <TR>
            <TD ALIGN="right"> Organization</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Organization" SIZE=35></TD>
          </TR>
          <TR>
            <TD ALIGN="right"> Address</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Address1" SIZE=35></TD>
          </TR>
          <TR>
            <TD ALIGN="right"> Address</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Address2" SIZE=35></TD>
          </TR>
          <tr>
            <TD ALIGN="right"> Address</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Address3" SIZE=35></TD>
          </tr>
          <tr>
            <TD ALIGN="right"> City</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="City" SIZE=35></TD>
          </tr>
          <tr>
            <TD ALIGN="right"> State/County</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="State" SIZE=35></TD>
          </tr>
          <TR>
            <TD ALIGN="right"> Post Code</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="PostCode" SIZE=35></TD>
          </TR>
          <TR>
            <TD ALIGN="right"> Country</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Country" SIZE=35></TD>
          </TR>
          <TR>
            <TD ALIGN="right"> Telephone</TD>
            <TD>
              <INPUT TYPE=TEXT NAME="Phone" SIZE=25 MAXLENGTH=25>
&nbsp; </TD>
          </TR>

          <TR align="center">
            <TD colspan="2" class="links">* denotes a required field</TD>
            </TR>
        </TABLE>
      </BLOCKQUOTE>
      <p>
        <INPUT name="SUBMIT" TYPE=SUBMIT VALUE="Submit Form">
        <INPUT name="RESET" TYPE=RESET VALUE="Reset Form">
        </p>
        </FORM></td>
      </tr>
    </table></td>
  </tr>
</table>
</BODY>
</HTML>
TIA[/b]
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: Check box value

Post by harrisonad »

ethoemmes wrote:The script doesn't seem to be recognising that the checkbox is checked.
The checkboxes, disctinct they are, wil only be submitted when checked. So, testing for it's existence will tell you if it is checked or not.

Code: Select all

$AddToML = isset($_POST['AddToML']) ? true : false;
Post Reply