Could someone find the fault in my form?

Discussion in 'PHP' started by lizzie87, Jul 26, 2006.

  1. #1
    Hi there,

    I just made this script and i'm a totally php newbie :p
    Somehow he doesn't send the e-mail with all the fild in fields.
    I was wondering if someone could help me finding the fault?
    And what i have to change to make it work?
    Thanks for the effort.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    	<title>Untitled</title>
    </head>
    
    <body>
    <form method="post" action="contact.php">
        <table>
            <tr>
                <td>Naam:</td>
                <td><input name="naam" /></td>
            </tr>
    		<tr>
                <td>Voorletters</td>
                <td><input name="voorletters" /></td>
            </tr>
    		<tr>
                <td>Geslacht:</td>
                <td>Man<input type="radio" name="geslacht" value="man" checked />Vrouw<input type="radio" name="geslacht" value="vrouw" /></td>
            </tr>
    		<tr>
                <td>Geboortedatum:</td>
                <td><input name="geboortedatum" /></td>
            </tr>
    		<tr>
                <td>Adres:</td>
                <td><input name="adres" /></td>
            </tr>
    		<tr>
                <td>Postcode:</td>
                <td><input name="postcode" /></td>
            </tr>
    		<tr>
                <td>Plaats:</td>
                <td><input name="plaats" /></td>
            </tr>
    		<tr>
                <td>Telefoon:</td>
                <td><input name="telefoon" /></td>
            </tr>
    		<tr>
                <td>Telefoon zakelijk:</td>
                <td><input name="telefoonzakelijk" /></td>
            </tr>
            <tr>
    			<td>E-mail:</td>
                <td><input name="mail" /></td>
            </tr>
    		 <tr>
    			<td>Werkgever:</td>
                <td><input name="werkgever" /></td>
            </tr>
    		 <tr>
    			<td>Lid COR/OR/OC:</td>
                <td>Ja<input type="radio" value="ja" name="lidcor" checked/>Nee<input type="radio" value="nee" name="lidcor"/></td>
            </tr>
    		 <tr>
    			<td>Machtiging aut. inc.:</td>
                <td>Ja<input type="radio" value="ja" name="machtiging" checked/>Nee<input type="radio" value="nee" name="machtiging"/> Kwartaal<input type="radio" value="kwartaal" name="machtiging"/> Halfjaar<input type="radio" value="nee" name="machtiging"/> Jaar<input type="radio" value="nee" name="machtiging"/></td>
            </tr>
    		 <tr>
    			<td>Gepensoineerd/VUT:</td>
                <td>Ja<input type="radio" value="ja" name="gepensioneerd" checked/>Nee<input type="radio" value="nee" name="gepensioneerd"/></td>
            </tr>
    		 <tr>
    			<td>Wat wilt u?:</td>
                <td>Aanmelden<input type="radio" value="aanmelden" name="watwiltu" checked/>Informatie<input type="radio" value="informatie" name="watwiltu"/>Mijn persoons gegevens wijzigen<input type="radio" value="gegevenswijzigen" name="watwiltu"/>Opzeggen<input type="radio" value="opzeggen" name="watwiltu"/></td>
            </tr>
    		<tr>
    			<td>Branche:</td>
    			<td>Banken<input type="radio" value="banken" name="branche" 				checked/>
    				Verzekeringen<input type="radio" value="verzekeringen" name="bracnhe"/>
    				Overige<input type="radio" value="verzekeringen" name="bracnhe"/>
            <tr>
                <td></td>
                <td><input type="submit" value="Verzenden" /></td>
            </tr>
        </table>
    </form>
    
    </body>
    </html>
    
    HTML:
    <?php
    if($_SERVER['REQUEST_METHOD']=='post'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche'].
    
        mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    }
    ?> 
    PHP:
     
    lizzie87, Jul 26, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to write <input name="naam" type="text" />
     
    mad4, Jul 26, 2006 IP
  3. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So i've put this in every line:

    <input name="werkgever" type="text"/>
    HTML:
    But it still doesn't work..
    Maybe it's the contact.php file which isn't right?
     
    lizzie87, Jul 26, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Instead of emailing the output to yourself just echo it to the page to help you debug it.

    Whats the output?
     
    mad4, Jul 26, 2006 IP
  5. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Maybe a stupid question but how do i echo it?
    I have to change the mail thing to echo and then contact.php?
     
    lizzie87, Jul 26, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    //mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    //this comments out the mail function
    
    echo"$bericht";
    //this echos the results
    PHP:
     
    mad4, Jul 26, 2006 IP
  7. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    After changing the code in this:


    <?php
    if($_SERVER['REQUEST_METHOD']=='post'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche'].
    
    //mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');//this comments out the mail function echo"$bericht";//this echos the results 
    }
    ?> 
    PHP:

    The output says:
    Parse error: parse error, unexpected '}' in /home/virtual/site85/fst/var/www/html/contact/contact.php on line 21
     
    lizzie87, Jul 26, 2006 IP
  8. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You need to seperate the code I posted so its not all on one line.
     
    mad4, Jul 26, 2006 IP
  9. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You have to close the bericht string properly on the last line:

    "\nBranche:\t".$_POST['branche'].
    PHP:
    to:

    "\nBranche:\t".$_POST['branche'];
    PHP:
    Note the . to ; change. All string end with ;

    That will get rid of the Parse error. Then echo $bericht like mad4 said to see if it's working.

    En als het niet werkt, helpen we wel weer :)
     
    T0PS3O, Jul 26, 2006 IP
  10. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Putted some enters in it..

    Now it says:



    Parse error: parse error, unexpected T_ECHO in /home/virtual/site85/fst/var/www/html/contact/contact.php on line 23
     
    lizzie87, Jul 26, 2006 IP
  11. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #11
    <?php
    if($_SERVER['REQUEST_METHOD']=='post'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche']; // <-- Note the ; instead of the . (. indicates more is soming, ; says string comes to an end)
    
        mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    }
    ?> 
    PHP:
    After adding the type="text" to the form, the above form handler should do the job.
     
    T0PS3O, Jul 26, 2006 IP
  12. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    He nog een nederlander ;)

    I changed the close tag..
    But now i just get a white screen..

    <?php
    if($_SERVER['REQUEST_METHOD']=='post'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche'];
    
    //mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    //this comments out the mail function
     
    echo"$bericht";//this echos the results 
    }
    ?> 
    PHP:

    So that means, that when i change it in email it will work?

    So i've changed it.. but now i dont get an email.. :(
     
    lizzie87, Jul 26, 2006 IP
  13. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Try this:

    <?php
    if($_SERVER['REQUEST_METHOD']=='post'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche'];
    
    //mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    //this comments out the mail function
     
    echo 'Het bericht:' . $bericht;//this echos the results 
    } else {
    echo 'Ooops - Server Request Method wasnt POST! It was in fact: ' . $_SERVER['REQUEST_METHOD'];
    }
    ?> 
    PHP:
    During debugging, always try to echo as much as you can, it's the easiest way to see where it goes wrong.
     
    T0PS3O, Jul 26, 2006 IP
  14. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    With that it says:

    Ooops - Server Request Method wasnt POST! It was in fact: POST
     
    lizzie87, Jul 26, 2006 IP
  15. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Change it to UPPERCASE in the if statement.

    <?php
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $bericht="Naam:\t".$_POST['naam'].
    "\nVoorletters:\t".$_POST['voorletters'].
    "\nGeslacht:\t".$_POST['geslacht'].
    "\nGeboortedatum:\t".$_POST['geboortedatum'].
    "\nAdres:\t".$_POST['adres'].
    "\nPostcode:\t".$_POST['postcode'].
    "\nPlaats:\t".$_POST['plaats'].
    "\nTelefoon:\t".$_POST['telefoon'].
    "\nTelefoon zakelijk:\t".$_POST['telefoonzakelijk'].
    "\nE-mail:\t".$_POST['mail'].
    "\nWerkgever:\t".$_POST['werkgever'].
    "\nLid COR/OR/OC:\t".$_POST['lidcor'].
    "\nMachtiging aut. inc.:\t".$_POST['machtiging'].
    "\nGepensioneerd/VUT:\t".$_POST['gepensioneerd'].
    "\nWat wilt u?:\t".$_POST['watwiltu'].
    "\nBranche:\t".$_POST['branche'];
    
    //mail('lisettebast@hotmail.com', 'Contact formulier', $bericht, 'From: '.$_POST['naam'].'<'.$_POST['mail'].'>');
    //this comments out the mail function
     
    echo 'Het bericht:' . $bericht;//this echos the results 
    } else {
    echo 'Ooops - Server Request Method wasnt POST! It was in fact: ' . $_SERVER['REQUEST_METHOD'];
    }
    ?> 
    PHP:
    With the help of a few strategic echo's you get to find it was something as silly as lowercase vs. uppercase :eek: Don't you hate that?

    Looks like the rest should work now.
     
    T0PS3O, Jul 26, 2006 IP
  16. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    And it works :)
    Thank you! I appreciate it!

    And yes i hate those simple things with lowercase and uppercase..... :D
     
    lizzie87, Jul 26, 2006 IP
  17. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Now all the male DP nerds have the e-mail address of what appears to be a 19 year old business woman with PHP skills... Expect to be flooded with emails :D
     
    T0PS3O, Jul 26, 2006 IP
  18. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #18
    haha well if i want some e-mails i think i have to train my php skills ;)
    but well i'm busy working on it.. gonna follow some training next year which will help i think :)
     
    lizzie87, Jul 26, 2006 IP
    T0PS3O likes this.