0

Help, I'm a php rookie. I have a functioning form to email script, but I can't seem to get it to display checked checkboxes. I am grateful for help on this!
Here's the checkbox (three checkboxes) and submit portion of my html form:

<label>Check all that apply: </label>
<p><input type="checkbox" name="checkbox1" value="mammography">   I want to receive medical updates about mammography</input></p>
   
   <p><input type="checkbox" name="checkbox2" value="blog">    Keep me connected — tell me about Tom's current writing</input></p>
   
   <p><input type="checkbox" name="checkbox3" value="book">   Notify me when Dr. Hudson's book is available</input></p>
<p> <strong>Click here to complete your request:</strong>
        <input type="submit" value="Subscribe"/>
           <br  /></p>

And here's the php script. I have three checkboxes and I'd like the email to owner to display the corresponding message to the checked checkboxes here:

if(isset($_POST['checkbox1'])) {
echo '<p>Send me medical updates about mammography.</p>';
{echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox2'])) {
echo '<p>Keep me connected with the latest blog posts.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox3'])) {
echo '<p>Let me know when the book is available.</p>';
echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
}

if (isset($_POST['Submit1'])) {
}

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by LittleMeemz
0

I see a bug in your code and try each of the following:

if(isset($_POST['checkbox1'])) {
echo '<p>Send me medical updates about mammography.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox2'])) {
echo '<p>Keep me connected with the latest blog posts.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox3'])) {
echo '<p>Let me know when the book is available.</p>';
echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
}

if (isset($_POST['Submit1'])) {
}
if($_POST['checkbox1']) {
echo '<p>Send me medical updates about mammography.</p>';
{echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if($_POST['checkbox2']) {
echo '<p>Keep me connected with the latest blog posts.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if($_POST['checkbox3']) {
echo '<p>Let me know when the book is available.</p>';
echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
}

if ($_POST['Submit1']) {
}
0

Welcome @LittleMeemz.

Always wrap programming code within posts in CODE-tags.

Edited by Nick Evan: Fixed formatting

0

I see a bug in your code and try each of the following:

if(isset($_POST['checkbox1'])) {
echo '<p>Send me medical updates about mammography.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox2'])) {
echo '<p>Keep me connected with the latest blog posts.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if(isset($_POST['checkbox3'])) {
echo '<p>Let me know when the book is available.</p>';
echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
}

if (isset($_POST['Submit1'])) {
}
if($_POST['checkbox1']) {
echo '<p>Send me medical updates about mammography.</p>';
{echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if($_POST['checkbox2']) {
echo '<p>Keep me connected with the latest blog posts.</p>';
echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
}
if($_POST['checkbox3']) {
echo '<p>Let me know when the book is available.</p>';
echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
}

if ($_POST['Submit1']) {
}

Thank you so much. I tried both options and I'm getting this error message: "Parse error: syntax error, unexpected $end in /home/yourjour/public_html/subscribe/subscribe.php on line 65". Maybe there's a problem somewhere else in my code. Here it is in its entirety if you have time to take a look.

<?php

// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$name = addslashes($_POST['name']);
@$textfield = addslashes($_POST['textfield']);

// Validation
if (strlen($name) == 0 )
{
header("Location: error.html");
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $textfield))
{
header("Location: error.html");
exit;
}

//Sending Email to form owner
$pfw_header = "From: $textfield\n"
  . "Reply-To: $textfield\n";
$pfw_subject = "request to receive notifications";
$pfw_email_to = "subscribe@yourjourneytohope.com";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "name: $name\n" 
. "textfield: $textfield\n"
. "has requested to be notified of the following updates:";


      if($_POST['checkbox1']) {
      echo '<p>Send me medical updates about mammography.</p>';
      {echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
      }
      if($_POST['checkbox2']) {
      echo '<p>Keep me connected with the latest blog posts.</p>';
      echo '<input type="checkbox" name="checkbox1" checked="checked" value="YES">';
      }
      if($_POST['checkbox3']) {
      echo '<p>Let me know when the book is available.</p>';
      echo '<input type="checkbox" name="checkbox3" checked="checked" value="YES">';
      }
      if ($_POST['Submit1']) {
      }
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;


//Sending auto respond Email to visitor
$pfw_header = "From: Dr.Tom@yourjourneytohope.com\n"
  . "Reply-To: subscribe@yourjourneytohope.com\n";
$pfw_subject = "Thank you from Dr. Tom at YourJourneytoHope.com";
$pfw_email_to = "$textfield";
$pfw_message = "Dear Friend,\n"
. "\n"
. "Thank you for subscribing to 'Your Journey to Hope.' Your email address will be added to my recipients for the updates you selected from www.yourjourneytohope.com. I hope the information encourages and helps you on your journey.\n"
. "\n"
. "To unscubscribe, please send an email to unsubscribe@yourjourneytohope.com.\n"
. "\n"
. "Dr. Tom";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header );

header("Location: thankyou.html");

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.