Multiple fields in php form

Discussion in 'PHP' started by lizzie87, Mar 9, 2006.

  1. #1
    Hello everyone,

    I'm busy with this script.. but somehow it isn't working. Hopefully somebody here knows the solution!

    I got a form but he doesn't display the filled in options in the e-mail.
    He does displays the name, emailaddress, phonenumber and message.. but not the other ones..

    The script is a little bit dutch.. (as i'm dutch ;) )
    I tried (print_r($_POST)) but that didn't work..

    Here's the script:

    <?
    // is niet 100% !!!
    function checkmail($mail)
    {
        $email_host = explode("@", $mail);
        $email_host = $email_host['1'];
        $email_resolved = gethostbyname($email_host);
    
        if ($email_resolved != $email_host && eregi("^[0-9a-z]([-_.~]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail))
            $valid = 1;
    
        return $valid;
    }
    
    // geef e-mail adres op van ontvanger
    $mail_ontv = "l.bast@ma-web.nl";
    
    // als er niet op submit is gedrukt, of als er wel op is gedrukt maar niet alles ingevoerd is
    if (!$_POST['submit'] || $_POST['submit'] && (!$_POST['naam'] || !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['msggs']))
    {
        if ($_POST['submit'] && (!$_POST['naam'] || !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['msggs']))   
        {
            echo "U bent uw naam, adres, telefoonnummer of e-mail adres vergeten in te vullen. Ook kan het zijn ";
            echo "dat u een verkeerd e-mail adres hebt ingevuld.<p>";
        }
          
        // form + tabel
        echo "<table border=\"0\" width=\"400px\" cellspacing=\"5\" cellpadding=\"0\">";
        echo "<form method=\"POST\" ACTION=\"" . $_SERVER['PHP_SELF'] . "\">";
        
        // space
        echo "<tr><td>Bestellijst:<br><br>
    	</td></tr>";
        /////////////////////////////////////////////lampen////////////////////////////////////////////
        // space
        echo "<tr><td><b>Tafels</b></td>
        	</tr>";
        
        
        // naam
        			echo "<tr>
        			<td>Foto</td>
        			<td>Beschrijving</td>
        			<td>Prijs</td>
        			<td>Aantal</td></tr>";
        
        			echo "<tr>
        			<td><img src=\"Images/Tafels/01.jpg\" width=\"40px\" height=\"40px\"></td>
        			<td>tafel 01</td> 
        			<td>&euro; 12,90,-</td>
        			<td><input type=\"text\" size=\"3\" name=\"tafel1\" value=\"" . $_POST['tafel1'] . "\"></td></tr>";
          
        // space
        echo "<tr><td>&nbsp;</td></tr>";
          
        // mail
        			echo "<tr>
        			<td><img src=\"Images/Tafels/02.jpg\" width=\"40px\" height=\"40px\"></td>
        			<td>tafel 02</td> 
        			<td>&euro; 12,90,-</td>
        			<td><input type=\"text\" size=\"3\" name=\"tafel2\" value=\"" . $_POST['tafel2'] . "\"></td></tr>";
          
        // space
        echo "<tr><td>&nbsp;</td></tr>";
        
        // telefoon
    
        			echo "<tr>
        			<td><img src=\"Images/Tafels/03.jpg\" width=\"40px\" height=\"40px\"></td>
        			<td>tafel 03</td> 
        			<td>&euro; 12,90,-</td>
        			<td><input type=\"text\" size=\"3\" name=\"tafel3\" value=\"" . $_POST['tafel3'] . "\"></td></tr>";
          
         // space
        echo "<tr><td>&nbsp;</td></tr>";
        
        // mail
    
        			echo "<tr>
        			<td><img src=\"Images/Tafels/04.jpg\" width=\"40px\" height=\"40px\"></td>
        			<td>tafel 04</td> 
        			<td>&euro; 12,90,-</td>
        			<td><input type=\"text\" size=\"3\" name=\"tafel4\" value=\"" . $_POST['tafel4'] . "\"></td></tr>";
      
        // space
        echo "<tr><td>&nbsp;</td></tr>";
        
         // sluit form + tabel
        echo "</form>";
        echo "</table>";
        
    
        
        // form + tabel
        echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"0\">";
        echo "<form method=\"POST\" ACTION=\"" . $_SERVER['PHP_SELF'] . "\">";
        
        // naam
        echo "<tr><td>Naam: </td><td><input type=\"text\" name=\"naam\" value=\"" . $_POST['naam'] . "\"></td></tr>";
          
        // space
        echo "<tr><td>&nbsp;</td></tr>";
          
        // mail
        echo "<tr><td>E-mail adres: </td><td><input type=\"text\" name=\"mail\" value=\"" . $_POST['mail'] . "\"></td></tr>";
        
        // space
        echo "<tr><td>&nbsp;</td></tr>";
        
        // telefoon
        echo "<tr><td>Telefoonnummer: </td><td><input type=\"text\" name=\"telefoon\" value=\"" . $_POST['telefoon'] . "\"></td></tr>";
        
        // space
        echo "<tr><td>&nbsp;</td></tr>";
          
        // mail
        echo "<tr><td>Overige opmerkingen: </td><td><TEXTAREA name=\"msggs\" ROWS=\"6\" COLS=\"35\">" . htmlentities($_POST['msggs']) . "</TEXTAREA></td></tr>";
          
        // space
        echo "<tr><td>&nbsp;</td></tr>";
          
        // button
        echo "<tr><td>&nbsp;</td></tr>";
        echo "<tr><td><input type=\"submit\" name=\"submit\" value=\"Versturen\"></td></tr>";
          
          
          
          
        // sluit form + tabel
        echo "</form>";
        echo "</table>";
    }
    // versturen naar
    else
    {      
        // set datum
        $datum = date("d.m.Y H:i");
          
        // set ip
        $ip = $_SERVER['REMOTE_ADDR'];
          
        $inhoud_mail = "===================================================\n";
        $inhoud_mail .= "Ingevulde bestellijst\n";
        $inhoud_mail .= "===================================================\n\n";
          
        $inhoud_mail .= "Naam: " . $_POST['naam'] . "\n";
        $inhoud_mail .= "E-mail adres: " . $_POST['mail'] . "\n";
        $inhoud_mail .= "Telefoonnummer: " . $_POST['telefoon'] . "\n";
        $inhoud_mail .= "Bericht:\n";
        $inhoud_mail .= $_POST['msggs'] . "\n\n";
        
        $inhoud_mail .= "tafel1: " . $_POST['tafel1'] . "\n";
        $inhoud_mail .= "tafel2: " . $_POST['tafel2'] . "\n";
        $inhoud_mail .= "tafel3: " . $_POST['tafel3'] . "\n";
        $inhoud_mail .= "tafel4: " . $_POST['tafel4'] . "\n";
        
        $inhoud_mail .= "Verstuurd op $datum via het ip " . $ip . "\n\n";
          
        $inhoud_mail .= "===================================================\n\n";
        
        // --------------------
        // spambot protectie
        // ------
        
        $headers = "From: " . $_POST['naam'] . " <" . $_POST['mail'] . ">";
        
        $headers = stripslashes($headers);
        $headers = str_replace("\n", "", $headers); // Verwijder \n
        $headers = str_replace("\r", "", $headers); // Verwijder \r
        $headers = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $headers)); // Slashes van quotes
        
        $_POST['onderwerp'] = str_replace("\n", "", $_POST['onderwerp']); // Verwijder \n
        $_POST['onderwerp'] = str_replace("\r", "", $_POST['onderwerp']); // Verwijder \r
        $_POST['onderwerp'] = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $_POST['onderwerp'])); // Slashes van quotes
         
        mail($mail_ontv, $_POST['onderwerp'], $inhoud_mail, $headers);
         
        echo "Uw bestelling is verstuurd";
        
        echo "<p>Bedankt voor uw bestelling. Wij zullen zo snel mogelijk ";
        echo "contact met u opnemen.</p>";
         
        echo "<p>We nemen alles serieus en zullen vertrouwelijk omgaan met de informatie ";
        echo "die we binnen krijgen. Uw gegevens zullen nooit aan derden worden verstrekt.</p>";
    }
    print_r($_POST);
    ?>
    
    
    </body>
    </html>
    
    PHP:
     
    lizzie87, Mar 9, 2006 IP
    T0PS3O likes this.
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    What version of PHP are you using? If you don't know, what's the URL for your site, and I'll check for you.

    Is there anything specific that's not working? Or just the inability to see the contents of $_POST?
     
    digitalpoint, Mar 9, 2006 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you post the parsed HTML output of the form?

    Everything looks OK....
     
    T0PS3O, Mar 9, 2006 IP
  4. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your reply!

    This is the link where i uploaded everything:

    http://www.lisettebast.nl/Webmenu/tafels.php

    It's just that he doesn't displays the filled in fields of:
    Tafel 1, 2, 3 and 4

    But what's strange is that he does display the filled in fields with name, phonenumer e-mail etc. But he doesn't do this with tafel 1,2,3 and 4...

    Really strange..
     
    lizzie87, Mar 9, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Somehow it gets split into two forms, according to the FireFox Webdeveloper Toolbar Form Analysis. One has the tafels, the other the rest that does show up.

    Found it. You echo </form> twice, splitting it up. See line 89 in your first post. Get rid of the form closing tag. It's too early.
     
    T0PS3O, Mar 9, 2006 IP
  6. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Got rid of the closing tag... uploaded the new file.. filled in the form and checked my e-mail.. but still nothing has changed :(
     
    lizzie87, Mar 9, 2006 IP
  7. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You were closing one form and then opening another on line 96, the browser will assume the first form needs to be closed as soon as it sees another being opened.

    Remove the second form opening tag and you should be OK.
     
    mad4, Mar 9, 2006 IP
  8. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah yeah, didn't spot the opening of the second. Indeed, there are two, only use one.
     
    T0PS3O, Mar 9, 2006 IP
  9. lizzie87

    lizzie87 Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    and that worked! Thanks a lot for helping me! :D
     
    lizzie87, Mar 9, 2006 IP