Question

Below is the PHP mailer code (part of it):

$message = '';
$message .= <<<TEXT

First Name:
{$_POST['name']}

Last Name:
{$_POST['lastname']}

Email:    
{$_POST['email']}

Phone:
{$_POST['phone']}

Accept:
{$_POST['checkbox']}

{$checkString}
TEXT;

Html form:

<form action="sendLid.php" method="POST">
    <img src="images/ajax.gif" id="ajaxPre" alt=""/>
    <input type="text" id="name" name="name" placeholder="שם פרטי" />
    <input type="text" id="lastname" name="lastname" placeholder="שם משפחה" />
    <input type="tel" id="phone" rel="טלפון"  name="phone" placeholder="טלפון"/>
    <input type="email" id="email" rel="מייל"  name="email" placeholder="מייל"/>
    <input type="submit" id="btn" value=""/>
    <input type="checkbox" checked="checked"  id="checkbox" name="checkbox" value=""/>
</form>

All works good. The problem is with the "Accept" line on the PHP file. Of course it will not send the value of the 'checkbox'. I tried to add if(isset) but I get an error, because I don't know how to insert the if statement with the <<< TEXT.

Was it helpful?

Solution

<input type="checkbox" checked="checked"  id="checkbox" name="checkbox" value=""/>

remove value tag from checkbox so you can check like below

$checkbox = (isset($_POST['checkbox']))?$_POST['checkbox']:'';

$message = '';
$message .= <<<TEXT

First Name:
{$_POST['name']}

Last Name:
{$_POST['lastname']}

Email:    
{$_POST['email']}

Phone:
{$_POST['phone']}

Accept:
{$checkbox}

{$checkString}
TEXT;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top