Jump to content

Recommended Posts

Hey

 

I'm trying to send my check-boxes with PHP. Before i added them to my script everything worked fine, i tested the form and i received the answers in my  inbox. when i tried to let the checkboxes work, it stopped working. Please help me out! !

I've added this to check my check-boxes:

 

if ($_POST['Keukens'] == 'on') {
$Keukens = "Ja";
} else {
$Keukens = "Nee";
    }
if ($_POST['Badkamers'] == 'on') {
$Badkamers = "Ja";
} else {
$Badkamers = "Nee";
    }
if ($_POST['Kasten'] == 'on') {
$Kasten = "Ja";
} else {
$Kasten = "Nee";
    }
if ($_POST['Kantoormeubels'] == 'on') {
$Kantoormeubels = "Ja";
} else {
   $Kantoormeubels = "Nee";
   }
if ($_POST['Tafels'] == 'on') {
$Tafels = "Ja";
} else {
$Tafels = "Nee";
}
if ($_POST['Overige'] == 'on') {
$Overige = "Ja";
} else {
$Overige = "Nee";
}

 

This is the delivery part:

else 
    { 
    $recipient = "sven@hotmail.com"; //Het email adres van de Ontvanger. 
    $subject = $_POST['sub']; //Onderwerp van de mail. 
    $header = "From: " . $_POST['uwemail'] . "\n"; 
    $mail_body = "Het Contact formulier werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; 
    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
    $mail_body .= "Voorletters: " . $_POST['voorletters'] . "\n"; 
$mail_body .= "Achternaam: " . $_POST['naam'] . "\n\n"; 
$mail_body .= "Adres: " . $_POST['adres'] . "\n"; 
$mail_body .= "Postcode: " . $_POST['postcode'] . "\n"; 
    $mail_body .= "Woonplaats: " . $_POST['plaats'] . "\n\n"; 
$mail_body .= "Telefoonnummer: " . $_POST['tel'] . "\n"; 
$mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
    $mail_body .= "Onderwerp: " . $_POST['sub']. "\n"; 
    $mail_body .= "Vraag: " . $_POST['field']. "\n\n";
$mail_body .= "Interesses:\n\n";
    $mail_body .= "Keukens: ".$Keukens."\n";
$mail_body .= "Badkamermeubels: ".$Badkamermeubels."\n";
$mail_body .= "Kasten: ".$Kasten."\n";
$mail_body .= "Kantoormeubels: ".$Kantoormeubels."\n";
$mail_body .= "Tafels: ".$Tafels."\n";
$mail_body .= "Overige: ".$Overige."\n";
$mail_body .= "\n\n -- Einde van het formulier--"; 
    mail($recipient, $subject, $mail_body, $header); 
    echo "<font color=\"#FFFFFF\"><center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u opnemen.<br>
Met vriendelijke groet,<br>Sven</b><br><br><br>"; 
    echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center></font>"; 
    }
} 
else 
{ 
?> 

 

This the HTML part:

 <font face="Verdana, Arial, Helvetica, sans-serif">
                  <label>
                  <input type="checkbox" name="Keukens" id="keuze1" value="Keukens"/>
                  <font color="#FFFF00" size="2"> <font size="1">Keukens</font></font></label>
                  <font color="#FFFF00" size="1"><br />
                  <label>
                    <input type="checkbox" name="Badkamers" id="keuze2" value="Badkamers"/>
                    Badkamermeubels</label>
                  <br />
                  <label>
                    <input name="Kasten" type="checkbox" id="keuze3" value="Kasten" />
                    Kasten</label>
                  <br />
                  <label>
                    <input type="checkbox" name="Kantoormeubels" id="keuze4" value="Kantoormeubels"/>
                    Kantoormeubels</label>
                  <br />
                  <label>
                    <input type="checkbox" name="Tafels" id="keuze5" value="Tafels"/>
                    Tafels</label>
                     <br />
                  <label>
                    <input type="checkbox" name="Overige" id="keuze6" value="Overige"/>
                    Overige</label>
                  </font><br />
                  </font></div>

 

Link to comment
https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/
Share on other sites

ow yeah lol sorry

 

line 98 is the "else" between the }{

97 }

98 else

99 {

 

echo "<font color=\"#FFFFFF\"><center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u 
opnemen.<br>
Met vriendelijke groet,<br> JPS</b><br><br><br>"; 
    echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center></font>"; 
    }
} 
else
{ 
?> 

<form action="<? echo $_SERVER ['PHP_SELF']; ?>" method="POST" name="contact"> 
  <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
      <td bgcolor="#000000"><table width="608" height="540" border="0" cellpadding="0" cellspacing="0">
        <tr>

 

Thanks man

 

<!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>PHP contact</title>
</head>

<body leftmargin="0" topmargin="0">
<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
?>
<?php
ini_set('display_errors', 'On');
$error_msg = ''; 
error_reporting(E_ALL | E_STRICT) ;
if ($_POST['Keukens'] == 'on') {
$Keukens = "Ja";
} else {
$Keukens = "Nee";
    }
if ($_POST['Badkamers'] == 'on') {
$Badkamers = "Ja";
} else {
$Badkamers = "Nee";
    }
if ($_POST['Kasten'] == 'on') {
$Kasten = "Ja";
} else {
$Kasten = "Nee";
    }
if ($_POST['Kantoormeubels'] == 'on') {
$Kantoormeubels = "Ja";
} else {
   $Kantoormeubels = "Nee";
   }
if ($_POST['Tafels'] == 'on') {
$Tafels = "Ja";
} else {
$Tafels = "Nee";
}
if ($_POST['Overige'] == 'on') {
$Overige = "Ja";
} else {
$Overige = "Nee";
}
if($_SERVER['REQUEST_METHOD']=="POST")
{ 
if(strlen($_POST['voorletters']) ==0)
    { $error_msg ="- Voorletters.<br>"; } 
if(strlen($_POST['naam']) ==0)
    { $error_msg ="- Achternaam.<br>"; } 
if(strlen($_POST['tel']) ==0)
    { $error_msg ="- Telefoonnummer.<br>"; } 
if(!preg_match("/^[_a-zA-Z0-9-]+(\.[*@([a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/", $_POST['uwemail']))
    { $error_msg .="- E-mailadres.<br>"; } 
if(strlen($_POST['field']) ==0)
    { $error_msg .="- Vraag.<br>"; } 

if(!empty($error_msg))
    { 
    //Een van de velden werd niet goed ingevuld 
    echo "<font color=\"#FFFFFF\"><center><b>Het formulier kan niet worden verzonden...<BR> 
Onderstaande gegevens zijn 'niet', of 'niet correct' ingevuld:</b><br><br>"; 
    echo $error_msg; 
    echo "<br>Probeer het <a href=javascript:history.back(1)>hier</a> opnieuw en vul alstublieft alle velden in.<br><br></center></font>"; 
    }
else 
    { 
    $recipient = "sven_jcvd@hotmail.com"; //Het email adres van de Ontvanger. 
    $subject = $_POST['sub']; //Onderwerp van de mail. 
    $header = "From: " . $_POST['uwemail'] . "\n"; 
    $mail_body = "Het Contact formulier werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; 
    $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 
    $mail_body .= "Voorletters: " . $_POST['voorletters'] . "\n"; 
$mail_body .= "Achternaam: " . $_POST['naam'] . "\n\n"; 
$mail_body .= "Adres: " . $_POST['adres'] . "\n"; 
$mail_body .= "Postcode: " . $_POST['postcode'] . "\n"; 
    $mail_body .= "Woonplaats: " . $_POST['plaats'] . "\n\n"; 
$mail_body .= "Telefoonnummer: " . $_POST['tel'] . "\n"; 
$mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 
    $mail_body .= "Onderwerp: " . $_POST['sub']. "\n"; 
    $mail_body .= "Vraag: " . $_POST['field']. "\n\n";
$mail_body .= "Interesses:\n\n";
    $mail_body .= "Keukens: ".$Keukens."\n";
$mail_body .= "Badkamermeubels: ".$Badkamermeubels."\n";
$mail_body .= "Kasten: ".$Kasten."\n";
$mail_body .= "Kantoormeubels: ".$Kantoormeubels."\n";
$mail_body .= "Tafels: ".$Tafels."\n";
$mail_body .= "Overige: ".$Overige."\n";
$mail_body .= "\n\n -- Einde van het formulier--"; 
    mail($recipient, $subject, $mail_body, $header); 
    echo "<font color=\"#FFFFFF\"><center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u opnemen.<br>
Met vriendelijke groet,<br> JPS</b><br><br><br>"; 
    echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center></font>"; 
    }
}
else 
{ 
?> 

<form action="<? echo $_SERVER ['PHP_SELF']; ?>" method="POST" name="contact"> 
  <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
      <td bgcolor="#000000"><table width="608" height="540" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td><table width="441" height="366" border="0" align="center" cellpadding="0" cellspacing="5" bordercolor="#FFFFFF" bgcolor="#000000">
            <tr>
              <td height="2" colspan="3"><div align="center"><font color="#FFFF00" size="2" face="Verdana, Arial, Helvetica, sans-serif">Contactformulier</font><br />
                      <br />
                </div>
                  <div align="left"></div>
                <div align="right"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">(* verplichte velden)</font></div></td>
            </tr>
            <tr>
              <td height="20" rowspan="2"><div align="left"></div></td>
              <td width="72" height="7"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Voorletters *</font></div></td>
              <td height="-4"><div align="left">
                  <input name="voorletters" type="text" size="10" />
                </div>
                  <div align="right"></div>
                <div align="right"></div></td>
            </tr>
            <tr>
              <td height="8"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Achternaam *</font></td>
              <td height="0"><input name="naam" type="text" id="naam" size="30" name:="name:""naam" /></td>
            </tr>
            <tr>
              <td height="0"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td>
              <td height="0"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Adres</font></div></td>
              <td height="1"><div align="left">
                  <input type="text" name="adres" size="30" maxlength="40" />
              </div></td>
            </tr>
            <tr>
              <td height="20" rowspan="2"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td>
              <td height="7"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Postcode</font></div></td>
              <td height="-4"><div align="left">
                  <input name="postcode" type="text" size="10" maxlength="7" />
                </div>
                  <div align="right"></div>
                <div align="center"></div>
                <div align="left"></div></td>
            </tr>
            <tr>
              <td height="8"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif"> Plaats</font></td>
              <td height="0"><input name="plaats" type="text" id="plaats" size="30" maxlength="40" /></td>
            </tr>
            <tr>
              <td height="1"> </td>
              <td height="1"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Tel *</font></div></td>
              <td height="1"><input type="text" name="tel" size="30" maxlength="15" /></td>
            </tr>
            <tr>
              <td width="6" rowspan="2" class="Kleiner"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td>
              <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Email *</font></div></td>
              <td height="-2"><div align="left">
                  <input name="uwemail" type="text" size="40" maxlength="40" />
              </div></td>
            </tr>
            <tr>
              <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Onderwerp</font></div></td>
              <td height="-2"><input name="sub" type="text" size="40" maxlength="40" /></td>
            </tr>
            <tr>
              <td width="6" class="Kleiner"> </td>
              <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Vraag *</font></div></td>
              <td rowspan="2"><div align="left">
                  <textarea name="field" cols="40" rows="2" wrap="virtual"></textarea>
              </div></td>
            </tr>
            <tr>
              <td height="15" colspan="2" class="Kleiner"><div align="left"></div></td>
            </tr>
            <tr>
              <td valign="top"><div align="right"></div></td>
              <td valign="top"><div align="left"><font color="#FFFF00" size="1" face="Verdana, Arial, Helvetica, sans-serif">Interesses</font></div></td>
              <td height="95"><div align="left">
                  <font face="Verdana, Arial, Helvetica, sans-serif">
                  <label>
                  <input type="checkbox" name="Keukens" id="Keukens"/>
                  <font color="#FFFF00" size="2"> <font size="1">Keukens</font></font></label>
                  <font color="#FFFF00" size="1"><br />
                  <label>
                    <input type="checkbox" name="Badkamers" id="Badkamers"/>
                    Badkamermeubels</label>
                  <br />
                  <label>
                    <input name="Kasten" type="checkbox" id="Kasten"/>
                    Kasten</label>
                  <br />
                  <label>
                    <input type="checkbox" name="Kantoormeubels" id="Kantoormeubels"/>
                    Kantoormeubels</label>
                  <br />
                  <label>
                    <input type="checkbox" name="Tafels" id="Tafels"/>
                    Tafels</label>
                     <br />
                  <label>
                    <input type="checkbox" name="Overige" id="Overige"/>
                    Overige</label>
                  </font><br />
                  </font></div></td>
            </tr>
            <tr>
              <td colspan="2"> </td>
              <td height="8"><div align="right">
                  <input type="reset" name="reset" id="reset" value="Herstel" />
                  <input type="submit" name="Submit" value="Verzenden" />
              </div></td>
            </tr>
          </table></td>
        </tr>
      </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> 
          <tr> 
          </tr> 
        </table> 
      </td> 
    </tr> 
  </table> 
</form> 

<?php 
} 
?>
</body>
</html>


you are specifying a value, so they wont ever have the value of "on".

 

That was your golden answer right there.  change all the checkbox values to "on"... don't remove them

 

Also, the value you put in the checkbox has no purpose if you're just going to change it.  You're best bet is to check if the variable even exists

if(isset($_POST['Keukens'])) $Keukens = "Jaa";
else $Keukens = "Nee";

 

 

can you give me an example of what you mean with check if the variables exists..

 

I just added the values of the checkboxes... they all got the value:"on"

I test it on the wamp server and it says:

 

Notice: Undefined index: Keukens in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php  on line 17

 

Notice: Undefined index: Badkamers in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 22

 

Notice: Undefined index: Kasten in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 27

 

Notice: Undefined index: Kantoormeubels in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 32

 

Notice: Undefined index: Tafels in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 37

 

Notice: Undefined index: Overige in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 42

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

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