svenjcvd Posted March 30, 2011 Share Posted March 30, 2011 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 = "[email protected]"; //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 More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 <input name="Kasten" type="checkbox" id="keuze3" value="Kasten" /> you are specifying a value, so they wont ever have the value of "on". When exactly is the problem ? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194565 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 Its not starting at all from the server.. So you mean i ve to remove the value at the HTML part? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194566 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 ive removed the values of the HTML part... Tested it at my wamp server: it says: Parse error: syntax error, unexpected T_ELSE in /Applications/XAMPP/xamppfiles/htdocs/contactformulier.php on line 98 Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194579 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 which is line 98 ? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194582 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 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> Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194584 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 probably a unclosed } block before that line. If you indent all of the code nicely it should just appear. Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194588 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 damn i cant find it... each open { gets closed properly i think... i ve check all of them... Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194601 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 damn i cant find it... each open { gets closed properly i think... i ve check all of them... Can you post the full script, in one code block so I can test it out. Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194608 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 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 = "[email protected]"; //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> Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194614 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 @date_default_timezone_set(@date_default_timezone_get()); The use of @ is bad, for some reason the way php handles this is very slow. Just saying Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194616 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 but how can you let php submit a form with no @? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194621 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 but how can you let php submit a form with no @? perhaps look up what @ does http://www.php.net/manual/en/language.operators.errorcontrol.php Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194624 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 damn, i didnt know it makes your form twice as slow if you use an @.. but if you're making a contact-form, there's no other solution right? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194632 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 Yeah there is, you need to design your script in a way that does not create errors. Then there are none to hide. Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194634 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 damn you mean a script to optimize another script...can you do that? i cant even find one (...) error in a simple form-script... lol you found any problem in my script by the way? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194639 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 damn you mean a script to optimize another script...can you do that? erm no, I mean this actual script should be written in a way that means there i no need to hide errors. Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194640 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 ok... I understand PHP a little bit, so i know for sure i'm not able to do that.. lol do you found jet what im doing wrong in my script? Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194641 Share on other sites More sharing options...
Zane Posted March 30, 2011 Share Posted March 30, 2011 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"; Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194643 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 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 Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194653 Share on other sites More sharing options...
Zane Posted March 30, 2011 Share Posted March 30, 2011 what does your code look like now Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194658 Share on other sites More sharing options...
svenjcvd Posted March 30, 2011 Author Share Posted March 30, 2011 Thank you so much for your help ! ! i fixed it.. it was the variable checking problem! RESPECT ! ! ! :DPEACE ! ! Link to comment https://forums.phpfreaks.com/topic/232217-cant-send-checkboxes/#findComment-1194683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.