html - PHP Send Script -- Checkbox verify -


url: http://medtransportcenter.com/medical-transportation/los-altos/ have updated form include checkbox. i'm trying send-form.php script recognize whether or not checkbox checked or not when sends confirmation email. did research , found following code trick checking whether checked. but, inserted , kept giving me syntax error when testing form. included additional code have php script , checkbox field below. please this.

my whole form html:

<div class="form-box"> <!-- form -->  <form id="proform" action="send-form.php" method="post" >  <h2 style="text-align:center;">request info</h2>         <h3 style="text-align:center;">free expert advice</h3> <div class="form-content"> <!-- form -->  <table cellpadding="0" cellspacing="0" border="0">  <!--tr> <td class="field-full" colspan="2">     <div class="label"><label for="www"><b>your website url</b></label></div>     <input id="www" class="required defaultinvalidurl url" maxlength="40" name="www" type="text" tabindex="2" value="http://" /> </td> </tr--> <tr> <th class="label" align="right"><label for="nameis">your name</label></td>:<td class="field">   <input id="nameis" class="required defaultinvalidemail nameis" maxlength="40" name="nameis" type="text" tabindex="2" value="required"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>                                    <tr> <th class="label" align="right"><label for="email">e-mail</label></td>:<td class="field">   <input id="email" class="required defaultinvalidemail email" maxlength="40" name="email" type="text" tabindex="3" value="required"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>     <tr> <th class="label" align="right"><label for="phone">best phone:</label></td> <td class="field">   <input id="phone" class="required defaultinvalidemail phone" maxlength="40" name="phone" type="text" tabindex="4" value="required" size="30"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>     <tr> <th class="label" align="right"><label for="bestime"> best time reach you:</label></td> <td class="field">   <input maxlength="40" size="30" name="bestime" type="text" tabindex="5" value="" /> </td> </tr>  <tr> <th class="label" align="right"><label for="phone"> origin:</label></td> <td class="field">   <input maxlength="40" size="30" name="origin" type="text" tabindex="5" value="" /> </td> </tr>  <tr> <th class="label" align="right"><label for="phone"> destination:</label></td> <td class="field">   <input maxlength="40" size="30" name="destination" type="text" tabindex="5" value="" /> </td> </tr>   <tr> <th class="label" align="right"><label for="msg"> message:</label></td> <td class="field">   <textarea rows="3" cols="31" name="msg" tabindex="6"></textarea> </td> </tr>  <tr> <th class="label"><label for="brochure">request brochures</label></td> <td class="field">   <input type="checkbox" name="brochure[]" value="yes" /> </td> </tr>         <!--tr> <td class="field-full" colspan="2">     <div class="label"><label for="msg"><b>other</b></label></div>   <textarea rows="3" cols="30" name="msg" tabindex="9"></textarea> </td> </tr-->  </table>  <div class="terms">by clicking 'send',<br/> accept our <a onclick="showterms()">privacy policy</a>. <br /><span style="font-size:14px;">phone: 800-282-6878.</span></div>  <div class="btn-box"><input class="button1" type="submit" value="send" tabindex="10" /></div>   <!-- end form --> </form>  </div> 

my php script

<?php  //$www = '';     $email = ''; $nameis = ''; $phone = ''; $bestime = ''; //$address = ''; $origin = ''; $destination = ''; $msg = ''; $brochure = '';  function getip() {if(isset($_server['http_x_forwarded_for'])){     $ip_address=$_server['http_x_forwarded_for']; }  if (!isset($ip_address)){         if (isset($_server['remote_addr']))          $ip_address=$_server['remote_addr']; } return $ip_address; }  if(isset($_post['brochure'])){ $brochure_checked = $_post['brochure'];}  else { $brochure_not_checked = $_post['brochure']; }   //taking info date, ip , user agent  $timestamp = date("y-m-d h:i:s"); $ip   = getip(); $host = gethostbyaddr($ip);  $user_agent = $_server["http_user_agent"];   //taking data form   //$www = addslashes(trim($_post['www']));    $email = addslashes(trim($_post['email'])); $nameis = addslashes(trim($_post['nameis'])); $phone = addslashes(trim($_post['phone'])); $bestime = addslashes(trim($_post['bestime'])); //$address = addslashes(trim($_post['address'])); $origin = addslashes(trim($_post['origin'])); $destination = addslashes(trim($_post['destination'])); $msg = addslashes(trim($_post['msg'])); $brochure = addslashes(trim($_post['brochure']));     //preparing mail  $headers = "mime-version: 1.0\n"; $headers .= "content-type: text/html; charset=utf-8\n"; $headers .= "content-transfer-encoding: quoted-printable\n"; $headers .= "from: $email\n";  $content = 'name: '.$nameis.'<br>'. 'e-mail: '.$email.'<br>'. 'phone: '.$phone.'<br>'. 'message: '.$msg.'<br>'. 'best time call: '.$bestime.'<br>'. 'origin: '.$origin.'<br>'. 'destination: '.$destination.'<br>'. 'requested brochure: '.$brochure.'<br>'. 'time: '.$timestamp.'<br>'. 'ip: '.$host.'<br>'. 'user agent: '.$user_agent;   //sending mail  mail("service@medtransportcenter.com","los altos, ca landing page contact", $content, $headers);   ?> 

well here friend, final , working version.

tested , working, complete a:

requested brochure: yes
or
requested brochure: no message in e-mail,
plus added echo'ed "thank you, message has been sent..." option @ end.

the form use:

<div class="form-box"> <!-- form -->  <form id="proform" action="send-form.php" method="post" >  <h2 style="text-align:center;">request info</h2>         <h3 style="text-align:center;">free expert advice</h3> <div class="form-content"> <!-- form -->  <table cellpadding="0" cellspacing="0" border="0">  <!--tr> <td class="field-full" colspan="2">     <div class="label"><label for="www"><b>your website url</b></label></div>     <input id="www" class="required defaultinvalidurl url" maxlength="40" name="www" type="text" tabindex="2" value="http://" /> </td> </tr--> <tr> <th class="label" align="right"><label for="nameis">your name</label></td>:<td class="field">   <input id="nameis" class="required defaultinvalidemail nameis" maxlength="40" name="nameis" type="text" tabindex="2" value="required"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>                                    <tr> <th class="label" align="right"><label for="email">e-mail</label></td>:<td class="field">   <input id="email" class="required defaultinvalidemail email" maxlength="40" name="email" type="text" tabindex="3" value="required"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>     <tr> <th class="label" align="right"><label for="phone">best phone:</label></td> <td class="field">   <input id="phone" class="required defaultinvalidemail phone" maxlength="40" name="phone" type="text" tabindex="4" value="required" size="30"          onfocus="if (this.value == 'required') {this.value = '';}"         onblur="if (this.value == '') {this.value = 'required';}" size="40" /> </td> </tr>     <tr> <th class="label" align="right"><label for="bestime"> best time reach you:</label></td> <td class="field">   <input maxlength="40" size="30" name="bestime" type="text" tabindex="5" value="" /> </td> </tr>  <tr> <th class="label" align="right"><label for="phone"> origin:</label></td> <td class="field">   <input maxlength="40" size="30" name="origin" type="text" tabindex="5" value="" /> </td> </tr>  <tr> <th class="label" align="right"><label for="phone"> destination:</label></td> <td class="field">   <input maxlength="40" size="30" name="destination" type="text" tabindex="5" value="" /> </td> </tr>   <tr> <th class="label" align="right"><label for="msg"> message:</label></td> <td class="field">   <textarea rows="3" cols="31" name="msg" tabindex="6"></textarea> </td> </tr>  <tr> <th class="label"><label for="brochure">request brochures</label></td> <td class="field">   <input type="checkbox" name="brochure"/> </td> </tr>         <!--tr> <td class="field-full" colspan="2">     <div class="label"><label for="msg"><b>other</b></label></div>   <textarea rows="3" cols="30" name="msg" tabindex="9"></textarea> </td> </tr-->  </table>  <div class="terms">by clicking 'send',<br/> accept our <a onclick="showterms()">privacy policy</a>. <br /><span style="font-size:14px;">phone: 800-282-6878.</span></div>  <div class="btn-box"><input class="button1" type="submit" value="send" tabindex="10" /></div>   <!-- end form --> </form>  </div> 

the php use:

<?php  //$www = '';     $email = ''; $nameis = ''; $phone = ''; $bestime = ''; //$address = ''; $origin = ''; $destination = ''; $msg = ''; $brochure = '';  function getip() { if(isset($_server['http_x_forwarded_for'])){     $ip_address=$_server['http_x_forwarded_for']; }  if (!isset($ip_address)){         if (isset($_server['remote_addr']))          $ip_address=$_server['remote_addr']; } return $ip_address; }  if(isset($_post['brochure'])){ $brochure = "yes"; }  else { $brochure = "no"; }   //taking info date, ip , user agent  $timestamp = date("y-m-d h:i:s"); $ip   = getip(); $host = gethostbyaddr($ip);  $user_agent = $_server["http_user_agent"];   //taking data form   //$www = addslashes(trim($_post['www']));    $email = addslashes(trim($_post['email'])); $nameis = addslashes(trim($_post['nameis'])); $phone = addslashes(trim($_post['phone'])); $bestime = addslashes(trim($_post['bestime'])); //$address = addslashes(trim($_post['address'])); $origin = addslashes(trim($_post['origin'])); $destination = addslashes(trim($_post['destination'])); $msg = addslashes(trim($_post['msg']));   //preparing mail  $headers = "mime-version: 1.0\n"; $headers .= "content-type: text/html; charset=utf-8\n"; $headers .= "content-transfer-encoding: quoted-printable\n"; $headers .= "from: $email\n";  $content = 'name: '.$nameis.'<br>'. 'e-mail: '.$email.'<br>'. 'phone: '.$phone.'<br>'. 'message: '.$msg.'<br>'. 'best time call: '.$bestime.'<br>'. 'origin: '.$origin.'<br>'. 'destination: '.$destination.'<br>'. 'requested brochure: '.$brochure.'<br>'. 'time: '.$timestamp.'<br>'. 'ip: '.$host.'<br>'. 'user agent: '.$user_agent;   //sending mail  mail("your_email@example.com","los altos, ca landing page contact", $content, $headers);  echo "thank you, message has been sent. contact possible.";  ?> 

the way set used isset posted value, assigned $brochure variable that, if set, variable equals "yes", , if not set, same variable equals "no".

(the code below added php, while other code removed)

if(isset($_post['brochure'])){ $brochure = "yes"; }  else { $brochure = "no"; } 

the syntax errors happening earlier, used addslashes , trim checkbox value, caused havoc.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -