FORM CHECK,

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elmr09
Forum Newbie
Posts: 7
Joined: Thu Aug 06, 2009 9:42 am

FORM CHECK,

Post by elmr09 »

Hi all!,

I was working on a form.
Now I was at the part for securing the mail input. and stuff.
It worked! perfect... But now I can't send anything anymore and it also doesn't give a error on the bottom.... :banghead:
Its driving me crazy,, I looked over it so many times..

Here the php:

Code: Select all

<?php
 
 
 
$aProducten = file("../content/novAA.txt");
 
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);
 
    return $value;
}
 
$aProducten = stripslashes_deep($aProducten);
$aBesteld = array();
$error = ""; 
$wanneer_dag = $_POST['wanneer_dag'];
$wanneer_maand = $_POST['wanneer_maand'];
$opmerking = $_POST['opmerkingen'];
$mail = $_POST['adres'];
$naam = $_POST['naam'];
$sex = $_POST['sex'];
$aan = "mail@tentyproductions.nl";
$onderwerp = "Bestelling Novotel Amsterdam Airport";
$aan2 = "".$mail."";
$onderwerp2 = "Uw Bestelling";
 
echo '<form method="post" action="'.$_SERVER['REQUEST_URI'].'">';
echo '<table border="0" class="bestel" cellspacing="0" width="470px">';
foreach($aProducten as $iKey => $sValue) {
echo '<tr><td class="randje"><input size="20" type="text" name="aantal_'.$iKey.'" id="aantal" class="textInput" /> <font size="1" color="#e2007a">ex.</font></td><td class="randje"> <td><td class="randje">'.$sValue.'</td></tr>';
}
 
echo '</table><p><div id="lijn"></div></p><p><table class="bestel" border="0">';
echo '<tr><td align="right"><font color="#e2007a">*</font> Naam: <input type="text" name="naam" id="naamblok" class="textInput" /></td>';
echo '<td align="right"><font color="#e2007a">*</font> <input type="radio" name="sex" value="Dhr. " />Dhr. <input type="radio" name="sex" value="Mvr. " />Mvr.</td></tr>';
echo '<tr><td align="right"><font color="#e2007a">*</font> Email: <input type="text" name="adres" id="mail" class="textInput" /></td></tr>';
echo '<tr><td align="right"><font color="#e2007a">*</font> Dag: <select name="wanneer_dag" id="wanneer" />
 
<option>dag</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select> <font color="#e2007a">*</font> Maand: <select name="wanneer_maand" id="wanneer" />
<option>januari</option>
<option>februari</option>
<option>maart</option>
<option>april</option>
<option>mei</option>
<option>juni</option>
<option>juli</option>
<option>augustus</option>
<option>september</option>
<option>oktober</option>
<option>november</option>
<option>december</option>
</select><td>&nbsp;Gewenste leverdatum</td><td>';
 
echo '<tr><p><td>Opmerkingen:</td></tr>';
echo '<tr><td><textarea name="opmerkingen" cols="40" rows="7"></textarea></td></p></tr>';
echo '<tr><td height="20px"><div id="lijn"></div><tr></td><td colspan="2"><input type="submit" value="Bestel" /> <input type="reset" value="Opnieuw" /></td></tr>';
echo '</table></p></form>';
 
 
 
 
if($_SERVER['REQUEST_METHOD'] == "POST") {
  for($i=0;$i<=count($aProducten);$i++) {
    if(isset($_POST['aantal_'.$i]) && is_numeric($_POST['aantal_'.$i])) {
      $aBesteld[] = array($i, $_POST['aantal_'.$i]);
    }
  }
 
$bericht = "Beste Stephan,\n\n Hier onder staat de bestelling van Amsterdam Airport.\n\n";
 
    
    foreach($aBesteld as $aProduct) {
    list($iProduct, $iAantal) = $aProduct;
    $bericht .= "• ".$iAantal." ex - ".$aProducten[$iProduct]." \n";
    }
    $bericht .= "Aanleverdatum: ".$wanneer_dag." ".$wanneer_maand."\n\n Opmerking:\n ".$opmerking." \n\n Met vriendelijke groet,\n ".$sex." ".$naam."";
 
$bericht2 = "Beste ".$sex." ".$naam.",\n\n Hier onder staat uw bestelling.\n\n";
 
    
    foreach($aBesteld as $aProduct) {
    list($iProduct, $iAantal) = $aProduct;
    $bericht2 .= "• ".$iAantal." ex - ".$aProducten[$iProduct]." \n";
    }
    $bericht2 .= "Aanleverdatum: ".$wanneer_dag." ".$wanneer_maand."\n\n Opmerking:\n ".$opmerking." \n\n Met vriendelijke groet,\n het Tenty team";
 
 
 
$emailPattern = '#^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$#i';
 
if (preg_match($emailPattern, $mail)) {
    $error = "U heeft tekens gebruikt die niet mogelijk zijn";
}
 
if (empty($_POST['naam']) || '')  {
   $error = "U heeft geen naam ingevult.";
}
 
 
if (empty($_POST['adres']) || '')  {
   $error = "U heeft geen email ingevult.";
}
 
 
if($error === "" && mail($aan, $onderwerp, $bericht, "FROM: $mail"))
if($error === "" && mail($aan2, $onderwerp2, $bericht2, "FROM: mail@tentyproductions.nl"))
 
 
{
header("Location: thankyou.html");
 
} else {
echo "$error";
}
exit(); 
}
 
?>
Does somebody see something wrong or?
Thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: FORM CHECK,

Post by superdezign »

Nothing jumps out at me as an obvious error, and much of it is not English, so it is not easy to follow. My suggestion is to be more specific on the problem. If you need help determining the problem, trying to echo debugging statements while the code runs. Detail each step of your process so you can see where it goes wrong.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: FORM CHECK,

Post by jackpf »

I can't spot any errors...

Have you got error reporting turned on?
elmr09
Forum Newbie
Posts: 7
Joined: Thu Aug 06, 2009 9:42 am

Re: FORM CHECK,

Post by elmr09 »

Hi Yeah sorry for the not english in the coding..

jackpf wrote:I can't spot any errors...

Have you got error reporting turned on?
Uhm I don't think so.. How does that work?

Oh yeah its not really a error I think.. I worked fine, I changed something, changed it back and it didn't work anymore :banghead:
When you click send. He doesn't say anything.. even when you didn't fill in anything..
And then if you fill everything in correctlly it still says nothing. And I also do not recieve a mail..

I will try to echo..

Thanks! :D

EDIT:

When I change $error to echo it does work he says I didn't fill the name input in.
Why he doesn't work when I use $error?? I think there is something wrong with this..

Code: Select all

$emailPattern = '#^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$#i';
 
if (preg_match($emailPattern, $mail)) {
    $error = "U heeft tekens gebruikt die niet mogelijk zijn";
}
 
if (empty($_POST['naam']) || '')  {
   echo "U heeft geen naam ingevult.";
}
 
 
if (empty($_POST['adres']) || '')  {
   echo "U heeft geen email ingevult.";
}
 
 
if($error === "" && mail($aan, $onderwerp, $bericht, "FROM: $mail"))
Thanksss
Last edited by elmr09 on Thu Aug 06, 2009 10:04 am, edited 1 time in total.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: FORM CHECK,

Post by aceconcepts »

What did you change to make it stop working?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: FORM CHECK,

Post by jackpf »

http://uk.php.net/manual/en/errorfunc.c ... lay-errors

You should use these functions to make sure you can see errors.

Like so:

Code: Select all

ini_set('display_errors', E_ALL);
error_reporting(E_ALL);
Yeah sorry for the not english in the coding..
Lol xD Yeah, that was a bit challenging....
elmr09
Forum Newbie
Posts: 7
Joined: Thu Aug 06, 2009 9:42 am

Re: FORM CHECK,

Post by elmr09 »

Okay I did the error thing.

Notice: Undefined index: wanneer_dag in /test2.php on line 21

Notice: Undefined index: wanneer_maand in /test2.phpon line 22

Notice: Undefined index: opmerkingen in /test2.php on line 23

Notice: Undefined index: adres in /test2.php on line 24

Notice: Undefined index: naam in /test2.php on line 25

Notice: Undefined index: sex in /test2.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /test2.php:35) in /test2.php on line 147

I got no idea what that is, lol.


thankss

EDIT:

Uhm I found this on the internet echo "<script type='text/javascript'>window.location='../dank.php';</script>";
instead of header.

But now it works when I click the send button. But he also go to that page even when i didn't fill anything in! :S
thats weird!

how that comes?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: FORM CHECK,

Post by jackpf »

Those errors are from trying to access an array value with a key that doesn't exist. You should use isset() to make sure a variable exists before doing something with it.

The header error is because you must have sent output to the page before sending the header. Headers must be sent before output.

And I don't know, what's your code?
Post Reply