0

I've tried to built a php form. However, it won't send.

html (index.html):

 <div class="row">
            <div id="Contact" class="container">
                <h1>Meer weten?</h1>
                <h2>Neem vrijblijvend contact op</h2>
                <div id="ContactBlock"> 
                    <form class="contactform" method="post" action="submitform.php">
                      <div class="FormTop">
                        <div class="half-left-cf">
                            <input type="text" id="input-name" name="name" placeholder="Naam (verplicht)">
                            <input type="text" id="input-email" name="email" placeholder="Email address (verplicht)">
                            <input type="text" id="input-telnr" name="telnr" placeholder="Telefoonnummer">
                          </div>
                          <div class="half-right-cf">
                            <textarea name="message" type="text" id="input-message" name="message" placeholder="Uw bericht"></textarea>
                          </div>  
                        </div>
                        <label>*Hoeveel is is 2+2? (Anti-spam)</label>
                        <input name="human" placeholder="Antwoord hier">
                          <input type="submit" value="Verzenden" id="input-submit">
                    </form> 
                </div>
            </div>     

php (submitform.php):

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$telnr = $_POST['telnr'];
$message = $_POST['message'];
$from = 'From: Contact Form'; 
$to = 'e-mail'; 
$subject = 'Hello';
$human = $_POST['human'];

$body = "Afkomstig van: $name\n E-Mail: $email\n Telnr:\n $telnr Bericht:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
    if ($human == '4') {                 
        if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Uw bericht werd goed verzonden. Wij contacteren u zo snel mogelijk.</p>';
    } else { 
        echo '<p>Er is iets misgegaan, probeer a.u.b. opnieuw!</p>'; 
    } 
} else if ($_POST['submit'] && $human != '4') {
    echo '<p>U heeft de anti-spam vraag niet correct ingevuld</p>';
}
} else {
    echo '<p>U heeft niet alle verplichte velden ingevuld</p>';
} 
} 
?>

When I press submit the browser returns a blanc page with /.../submitform.php in the url-bar.

This happens both in an online environment as well as on localhost.

Am I doing something wrong? Thanks

BjornsBot
  • 33
  • 8
  • where are your files located? – ImAtWar Jun 01 '17 at 17:59
  • That's because your action is sending the browser to that page, so it will go to submitform.php in that case, but how is your file structure set up – clearshot66 Jun 01 '17 at 18:00
  • my submitform.php file is in the same map as the index.html if that's what you are asking. Sorry, I'm really new at all this and I've been searching for hours, but can't seem to fix it :-) – BjornsBot Jun 01 '17 at 18:02
  • ` – Funk Forty Niner Jun 01 '17 at 18:03
  • btw, how are you running this from, a webserver or off our own pc and as `file:///`? Your *"returns a blanc page with /.../submitform.php in the url-bar"* suggests it. – Funk Forty Niner Jun 01 '17 at 18:04
  • 2
    Oh nevermind.. you need to set the submit button to `name='submit'` and then instead of `if($_POST['submit']` check `if(isset($_POST['submit']))` – brianforan Jun 01 '17 at 18:05
  • also `if ($_POST['submit'])` will never happen. – Funk Forty Niner Jun 01 '17 at 18:05
  • 1
    @brianforan even then, that doesn't explain the *"returns a blanc page with /.../submitform.php in the url-bar"* - that tells me they're using `file:///` rather than `http://localhost`. – Funk Forty Niner Jun 01 '17 at 18:07
  • @Fred-ii- not really, the page would still redirect to `submitform.php` but if there is nothing happening in the file it will just return a white page. What else would it return anyway? There's no redirect. But I guess my original post about renaming to index.php is wrong, because clearly it is redirecting. – brianforan Jun 01 '17 at 18:09
  • 1
    @brianforan actually that worked, thanks a lot! Can I flag you for correct answer somewhere? P.s. Is there an easy way to trigger the messages on the same page instead of going to a new page / or at least to automatically return to the index page in a few seconds after sending? – BjornsBot Jun 01 '17 at 18:10

1 Answers1

0

If you not sure about your folder structure just use this simple trick.

Change post url to absolute one like http://www.example.com/xyz/submitform.php

In local

http://www.localhost/xyz/submitform.php

Instead of trying simple submitform.php

Subi
  • 107
  • 8