1

I have been trying to add php to a bootstrap form via the following tutorial: https://bootstrapbay.com/blog/working-bootstrap-contact-form/. But nothing happens when I click the submit button - I just go back/stay to the same page with an empty form. I don't receive an email nor any error actions when I don't fill out some fields either. Below my code. The name of the document is werkwijze.php. Does someone have an idea what I'm doing wrong? Thanks a lot in advance!

<?php
              if (isset($_POST['submit'])){
                  $voornaam = $_POST['voornaam'];
                  $familienaam = $_POST['familienaam'];
                  $email = $_POST['email'];
                  $tel = $_POST['tel'];
                  $vraag = $_POST['vraag'];
                  $from = '[email protected]'; 
                  $to = '[email protected]'; 
                  $subject = 'Vraag van op uw website www.tbep.be';

                  $body = "From: $voornaam $familienaam\n E-Mail: $email\n Telefoon: $tel\n Vraag: $vraag";

                  // Check if name has been entered
                  if (!$_POST['voornaam']) {
                      $errVoornaam = 'Gelieve uw voornaam op te geven';
                  }

                  if (!$_POST['familienaam']) {
                      $errFamilienaam = 'Gelieve uw familienaam op te geven';
                  }

                  // Check if email en phone has been entered and is valid
                  if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                      $errEmail = 'Gelieve uw emailadres op te geven';
                  }

                  if (!$_POST['tel']) {
                      $errTel = 'Gelieve uw telefoonnummer op te geven';
                  }

                  //Check if message has been entered
                  if (!$_POST['vraag']) {
                      $errVraag = 'Gelieve uw vraag te stellen';
                  }


          // If there are no errors, send the email
          if (!$errVoornaam && !$errFamilienaam && !$errEmail && !$errTel && !$errVraag) {
              if (mail ($to, $subject, $body, $from)) {
                  $result='<div class="alert alert-success">Hartelijk dank. Ik neem zo snel mogelijk contact met u op!</div>';
              } else {
                  $result='<div class="alert alert-danger">Sorry, er was een probleem met het versturen van dit formulier. Alternatief kan u ons een email sturen op [email protected]</div>';
              }
          }
              }
          ?> 

        <form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="text/plain">
            <div class="form-group">
              <label class="control-label col-sm-3" for="voornaam">Voornaam:</label>
              <div class="col-sm-9">
                <input type="text" class="form-control" id="voornaam" name="voornaam" placeholder="Voornaam">
                <?php echo "<p class='text-danger'>$errVoornaam</p>";?>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-sm-3" for="familienaam">Familienaam:</label>
              <div class="col-sm-9">
                <input type="text" class="form-control" id="familienaam" name="familienaam" placeholder="Familienaam">
                <?php echo "<p class='text-danger'>$errFamilienaam</p>";?>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-sm-3" for="email">Email:</label>
              <div class="col-sm-9">
                <input type="email" class="form-control" id="email" name="email" placeholder="Email">
                <?php echo "<p class='text-danger'>$errEmail</p>";?>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-sm-3" for="telefoon">Telefoonnummer:</label>
              <div class="col-sm-9">
                <input type="tel" class="form-control" id="tel" name="tel" placeholder="Telefoonnummer">
                <?php echo "<p class='text-danger'>$errTel</p>";?>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-sm-3" for="vraag">Uw vraag:</label>
              <div class="col-sm-9">
                <textarea class="form-control" rows="5" id="vraag" name="vraag" placeholder="Uw vraag"></textarea>
                <?php echo "<p class='text-danger'>$errVraag</p>";?>
              </div>
            </div>               
            <div class="form-group">        
              <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" id="submit" name="submit" value="Send" class="btn btn-default">Versturen</button>
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-9 col-sm-offset-3">
                  <?php echo $result; ?>    
              </div>
          </div>
          </form>

1 Answer 1

0

Please Remove enctype="text/plain" from your form.

<form class="form-horizontal" role="form" action="werkwijze.php" method="post">

Or use

<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.