Jump to content

checkboxes and email form php ugh!


grk101

Recommended Posts

hi guys,,

i have searched for help but i am getting more lost with the array's etc :(

so i decided to make a post.

 

this is my script below, the problem is i can't get the checkboxes to send the info that is selected :( So if all of them are select they all send, if one selected one sends and so on..

 

i tried to make it an array by putting name="roominformation[]" but the word array would only send.

 

thanks so much for any help

 

<?			





$to = "[email protected]";


if (!isset($_POST['Submit'])) {

  showForm();

} else { //form submitted

  $error = 0;



  if(!preg_match("/^(?:[\w\d]+\.?)+@(??:[\w\d]\-?)+\.)+\w{2,4}$/", $_POST['email'])) {
    $error = 1;
    $errstr[] = "Please enter a valid email address";
  }


// if(empty($_POST['message']) || preg_match("/^enter your message here$/i", $_POST['message'])) {
  //  $error = 1;
  //  $errstr[] = "Please enter a message";
// }

  if(empty($_POST['imagetext'])) {
    $error = 1;
    $errstr[] = "Please validate the image code";
  } else {
    include "securimage.php";
    $img = new Securimage();
    $valid = $img->check($_POST['imagetext']);

    if(!$valid) {
      $error = 1;
      $errstr[] = "The code you entered was incorrect";
    } 
  }

  if ($error == 1) {
    echo "<center>\n<font style=\"color: #FF0000\">\n";
    foreach($errstr as $err) {
      echo "<li> " . $err . "</li>\n";
    }
    echo "</font>\n</center>\n<br />\n\n";

    showForm();

  } else {
    @mail($to, "Room info - " . $_POST['firstname'],

 "\n\n Room Information:\n" . $_POST['roominformation'] .


        "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']);

      echo "<center><font color=black>\nThanks for contacting us.  
          </font> <br /><br />"
        ."<font color=black>Click <a href=\"#\" onclick=\"self.close()\">here</a> to close this window.</font>";


  }

} //else submitted



function showForm()
{


  echo <<<EOD
             
  		
<div id="form">
<form method="POST">

<table border="0" class="showin">

  <tr>
    <td>Living Room 
      <input name="roominformation"  type="checkbox"  value="Living Room"/></td>
    <td>Dining Room
      <input name="roominformation"  type="checkbox"  value="Dining Room"/></td>
    <td>Great Room 
      <input name="roominformation"  type="checkbox" value="Great Room"/></td>
    <td>Family Room 
      <input name="roominformation"  type="checkbox"  value="Family Room"/></td>
    <td>Den 
      <input name="roominformation"  type="checkbox"  value="Den"/></td>
    <td>Library 
      <input name="roominformation"  type="checkbox"  value="Library"/></td>
    <td>Laundry 
      <input name="roominformation"  type="checkbox"  value="Laundry"/></td>
  </tr>
</table>

        

</form>
</div>
EOD;
}



?>

Link to comment
https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/
Share on other sites

okay this is going to sound very stupid..

 

but where do i put that on my form .....

 

will that line pass my form? or do i still have to have the value

 

@mail($to, "Room info - " . $_POST['firstname'],

 

"\n\n Room Information:\n" . $_POST['roominformation'] .

 

 

        "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']);

Put it where you're checking for errors.

 

Something like should work:

$cb_values = $_POST["roominformation"];

$cb_num = count($cb_values); // this variable will hold the # of checkboxes that are checked
$total_boxes = 7; // this variable will hold the # of total checkboxes

if($cb_num < $total_boxes) // if the # of checked boxes is less than the total amount of checkboxes
{
$error = 1;
$errorstr[] = "zomg";
}

Then add it all together in a string and stick it in the mail() function or however you want to do it.

This is how i put it, knowning me right now i propbably did something wrong.

 

sorry for my bad grammar above,

<?			





$to = "[email protected]";


if (!isset($_POST['Submit'])) {

  showForm();

} else { //form submitted

  $error = 0;



  if(!preg_match("/^(?:[\w\d]+\.?)+@(??:[\w\d]\-?)+\.)+\w{2,4}$/", $_POST['email'])) {
    $error = 1;
    $errstr[] = "Please enter a valid email address";
  }


// if(empty($_POST['message']) || preg_match("/^enter your message here$/i", $_POST['message'])) {
  //  $error = 1;
  //  $errstr[] = "Please enter a message";
// }

  if(empty($_POST['imagetext'])) {
    $error = 1;
    $errstr[] = "Please validate the image code";
  } else {
    include "securimage.php";
    $img = new Securimage();
    $valid = $img->check($_POST['imagetext']);

    if(!$valid) {
      $error = 1;
      $errstr[] = "The code you entered was incorrect";
    } 
  }

  if ($error == 1) {
    echo "<center>\n<font style=\"color: #FF0000\">\n";
    foreach($errstr as $err) {
      echo "<li> " . $err . "</li>\n";
    }
    echo "</font>\n</center>\n<br />\n\n";
$cb_values = $_POST["roominformation"];

$cb_num = count($cb_values); // this variable will hold the # of checkboxes that are checked
$total_boxes = 7; // this variable will hold the # of total checkboxes

if($cb_num < $total_boxes) // if the # of checked boxes is less than the total amount of checkboxes
{
$error = 1;
$errorstr[] = "zomg";
}
    showForm();

  } else {
    @mail($to, "Room info - " . $_POST['firstname'],

"\n\n Room Information:\n" . $_POST['roominformation'] .


        "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']);

      echo "<center><font color=black>\nThanks for contacting us.  
          </font> <br /><br />"
        ."<font color=black>Click <a href=\"#\" onclick=\"self.close()\">here</a> to close this window.</font>";


  }

} //else submitted



function showForm()
{


  echo <<<EOD
             
  		
<div id="form">
<form method="POST">

<table border="0" class="showin">

  <tr>
    <td>Living Room 
      <input name="roominformation"  type="checkbox"  value="Living Room"/></td>
    <td>Dining Room
      <input name="roominformation"  type="checkbox"  value="Dining Room"/></td>
    <td>Great Room 
      <input name="roominformation"  type="checkbox" value="Great Room"/></td>
    <td>Family Room 
      <input name="roominformation"  type="checkbox"  value="Family Room"/></td>
    <td>Den 
      <input name="roominformation"  type="checkbox"  value="Den"/></td>
    <td>Library 
      <input name="roominformation"  type="checkbox"  value="Library"/></td>
    <td>Laundry 
      <input name="roominformation"  type="checkbox"  value="Laundry"/></td>
  </tr>
</table>

        

</form>
</div>
EOD;
}

well i got this..

below.. the problem is.. if no checkbox is selected, i get a forech error. not sure what to do

 

  $message .= "\n\n Room information:\n";      
     
  // put the contents of each index of roominformation into room_info      
  foreach($_POST['roominformation'] as $room_info)        
  {      
      $message .= "$room_info\n";      
  }      

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.