Jump to content
HensterRSA

check box not sending the selected box in the message body

Recommended Posts

please help I know it's something silly , i cannot get the selecter checkboxes to send to the mail index.php

<?phpsession_name("fancyform");session_start();$_SESSION['n1'] = rand(1,20);$_SESSION['n2'] = rand(1,20);$_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2'];$str='';if($_SESSION['errStr']){    $str='<div class="error">'.$_SESSION['errStr'].'</div>';    unset($_SESSION['errStr']);}$success='';if($_SESSION['sent']){    $success='<h1>Thank you!</h1>';       $css='<style type="text/css">#contact-form{display:none;}</style>';       unset($_SESSION['sent']);}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Henster Feedback Form </title><link rel="stylesheet" type="text/css" href="jqtransformplugin/jqtransform.css" /><link rel="stylesheet" type="text/css" href="formValidator/validationEngine.jquery.css" /><link rel="stylesheet" type="text/css" href="demo.css" /><?=$css?><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript" src="jqtransformplugin/jquery.jqtransform.js"></script><script type="text/javascript" src="formValidator/jquery.validationEngine.js"></script><script type="text/javascript" src="script.js"></script></head><body><div id="main-container">    <div id="form-container">    <h1>Hensters Feedback Form</h1><br><br>    <h2>Drop us a line and we will get back to you</h2>       <form id="contact-form" name="contact-form" method="post" action="submit.php">	  <table width="100%" border="0" cellspacing="0" cellpadding="5">	    <tr>		  <td width="15%"><label for="name"><Name</label></td>		  <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>		  <td width="15%" id="errOffset"> </td>	    </tr>	    <tr>		  <td><label for="email">Email</label></td>		  <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>		  <td> </td>	    </tr>	    <tr>		  <td><label for="subject">Subject</label></td>		  <td><select name="subject" id="subject">		    <option value="" selected="selected"> - Choose -</option>		    <option value="Question">Question</option>		    <option value="Business proposal">Business proposal</option>		    <option value="Advertisement">Advertising</option>		    <option value="Complaint">Complaint</option>		  </select>		  </td>		  <td> </td>	    </tr>	    <tr>		  <td valign="top"><label for="message">Message</label></td>		  <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td>		  <td valign="top"> </td>	    </tr>	    <tr>		 <td><label for="series">series</label></td>		 <td><input type="checkbox" name="series" id="series" value="series ” /><?=$_SESSION['post']['value']?> </td>	  <td valign="top"> </td>   <tr>		 <td> <label FOR="blue">blue</label></td>	    <td> <input type="checkbox" name="check[]" value="blue"><?=$_SESSION['post']['value']?></td></tr><br>    <h2>Select the Series </h2>	    <tr>		  <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>		  <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>		  <td valign="top"> </td>	    </tr>	    <tr>		  <td valign="top"> </td>		  <td colspan="2"><input type="submit" name="button" id="button" value="Submit" />		  <input type="reset" name="button2" id="button2" value="Reset" />	    </tr>	  		  <?=$str?>		  <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td>	    </tr>	  </table>	  </form>	  <?=$success?>    </div>    <div class="tutorial-info">       This is a Henster Feedback Page</div></body></html>

and my submit.php

 ?php/* config start */$emailAddress = 'info@henster.co.za';/* config end */require "phpmailer/class.phpmailer.php";session_name("fancyform");session_start();foreach($_POST['check'] as $value) {$check_msg .= "Checked: $value\n";}foreach($_POST as $k=>$v){    if(ini_get('magic_quotes_gpc'))    $_POST[$k]=stripslashes($_POST[$k]);       $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));}$err = array();if(!checkLen('name'))    $err[]='The name field is too short or empty!';if(!checkLen('email'))    $err[]='The email field is too short or empty!';else if(!checkEmail($_POST['email']))    $err[]='Your email is not valid!';if(!checkLen('subject'))    $err[]='You have not selected a subject!';if(!checkLen('message'))    $err[]='The message field is too short or empty!';if((int)$_POST['captcha'] != $_SESSION['expect'])    $err[]='The captcha code is wrong!';if(count($err)){    if($_POST['ajax'])    {        echo '-1';    }    else if($_SERVER['HTTP_REFERER'])    {        $_SESSION['errStr'] = implode('<br />',$err);        $_SESSION['post']=$_POST;               header('Location: '.$_SERVER['HTTP_REFERER']);    }    exit;}$msg='Name:    '.$_POST['name'].'<br />Email:    '.$_POST['email'].'<br />IP:    '.$_SERVER['REMOTE_ADDR'].'<br /><br />Series Selected : '.$_POST['value'].'<br />Message:<br /><br />'.nl2br($_POST['message']).'';if($_POST['consultancy']==1) { $msg.='Consultancy: '.$_POST['consultancy']; }$mail = new PHPMailer();$mail->IsMail();$mail->AddReplyTo($_POST['email'], $_POST['name']);$mail->AddAddress($emailAddress);$mail->SetFrom($_POST['email'], $_POST['name']);$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";$mail->MsgHTML($msg);$mail->Send();unset($_SESSION['post']);if($_POST['ajax']){    echo '1';}else{    $_SESSION['sent']=1;       if($_SERVER['HTTP_REFERER'])        header('Location: '.$_SERVER['HTTP_REFERER']);       exit;}function checkLen($str,$len=2){    return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;}function checkEmail($str){    return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);}?>

Share this post


Link to post
Share on other sites

name="series" id="series" foreach($_POST['check'] as $value) Series Selected : '.$_POST['value'].'<br /> there you go, your checkbox name was series your $_post['']; is check, and your series selected is $_post['value'] name="series" <---- try changing them to that well thats as much as i can give out, im not that well in this hehehe but i try to help as much, so i hope it worked

Edited by DDs1

Share this post


Link to post
Share on other sites
Nope
sorry about that i not too long edited what i said, check the above replied thanks

Share this post


Link to post
Share on other sites

if you use name as name=check[] , the value will be stored as $_POST['value'][0]...and it will append each entry as many checkbox will be there,in second dimension of the array. wherenever in doubt you can use echo '<pre>' . print_r($_POST),true) . '</pre>'; to see how your data is there.

Share this post


Link to post
Share on other sites
http://w3schools.invisionzone.com/index.php?showtopic=44350 check this for basic debug technuiqe and also you should enable "error_reporting" to E_ALL|E_STRICT and "display_error" to true , either in your php.ini or using ini_set() . it will help you to debug. http://php.net/ini_set

Share this post


Link to post
Share on other sites

hi im a big noob ,,, lol maybe one day i will get this ok i placed this in my codey on the index.php <tr> <td><label for="series">series</label></td> <td><input type="checkbox" name="series" id="series" value="series ” /><?=$_POST['value'][0]?> </td> <td valign="top"> </td> <tr> <td> <label FOR="blue">blue</label></td> <td> <input type="checkbox" name="check[]" value="blue"><?=$_POST['value'][0]?> </td></tr>and this in my send.php$msg='Name: '.$_POST['name'].'<br />Email: '.$_POST['email'].'<br />IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />Series Selected : '.$_POST['value'].'<br /> but when i select them i get an empty result for the tick boxes

Share this post


Link to post
Share on other sites

yeah he needs to change $_Post['value'] to $_Post['series'] or w.e the name is

Share this post


Link to post
Share on other sites

give it a different name and place that name into a $_Post[] function and call on it with the variable

Share this post


Link to post
Share on other sites
<input type="checkbox" name="series" id="series" value="series ” /><?=$_POST['value'][0]?>and<input type="checkbox" name="blue" value="blue"><?=$_POST['value'][0]?>
what are you trying to do? im lost, where did the [] came from?

Share this post


Link to post
Share on other sites

fom a previus post .. im also lost kinldy give me the correct coding .. basically i have multible check boxes and only want the selected ones to send to email everything ells works

Share this post


Link to post
Share on other sites
fom a previus post .. im also lost kinldy give me the correct coding .. basically i have multible check boxes and only want the selected ones to send to email everything ells works
i can not give you the coding, that would be doing it for you, what i can do is say what you need to do. for each checkbox, the names need to be different, and for $_Post['']; needs to be the name of the checkbox, like i said above if you go back to the first reply i made it give you a full description. you have $_post['value'] that should not be there since non of your checkbox names is value
<input type="checkbox" [color=#ff0000]name="series" [/color]value="blue"></td>

since the above html form field have a name as series then in your php code it should have a variable that equal to $_post['series']; like this.my html code

 <input type="checkbox" [color=#ff0000]name="series" [/color]value="blue"></td>

my php code

<?php$var = $_POST['series'];?>

note that my variable is $var and my post name is series which matches up with my checkbox name

Share this post


Link to post
Share on other sites

<input type="checkbox" name="series[]" value="foo ” /><input type="checkbox" name="series[]" value="bar ” /><input type="checkbox" name="series[]" value="baf ” /> if you use post the data will be available in $_POST['series'][0]='foo' $_POST['series'][1]='bar' etc what [] mean is its adds a new index every time it executes and $_POST,$_GET are not functions it is super global array.

Share this post


Link to post
Share on other sites
<input type="checkbox" name="series[]" value="foo ” /><input type="checkbox" name="series[]" value="bar ” /><input type="checkbox" name="series[]" value="baf ” /> if you use post the data will be available in $_POST['series'][0]='foo' $_POST['series'][1]='bar' etc what [] mean is its adds a new index every time it executes and $_POST,$_GET are not functions it is super global array.
ok i have done this in html
<td><input type="checkbox" name="series" id="series[]" value="blue"  /> </td><td><input type="checkbox" name="series" id="series[]" value="red"  /> </td> 

in my submit.php on top

 $var = $_POST['series'];  foreach($_POST['check'] as $value) {$check_msg .= "Checked: $value\n";}

in my submit.php below

 $msg='Name:	'.$_POST['name'].'<br />Email:	'.$_POST['email'].'<br />IP:	'.$_SERVER['REMOTE_ADDR'].'<br /><br />Series Selected : '.$_POST['series'].'<br />		   Message:<br /><br /> 

only one clour shows when i select 2

Edited by HensterRSA

Share this post


Link to post
Share on other sites
Series Selected : '.$_POST['series'].'<br />
you can do it like this if you want to see all the selected checkbox dataecho 'Selected series:' . implode(',',$_POST['series']); $_POST['series'] is array itself which holds other checkbox data.It is a two dimensional array. you can read about it here and how does it work http://php.net/language.type.array http://php.net/implode

Share this post


Link to post
Share on other sites

The names need the brackets on the end, not the IDs. IDs need to be unique, if you're not using Javascript to access the checkboxes then you don't need to give them IDs.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...