Blank Blank - 5 months ago 9
HTML Question

Get the value of input and show in letter

Im trying to get the value of an input and display it in a letter.
The letter is visible a section which is visible after the user fills in the input with his/her name to make the letter more personally.

<section id="formulier">
<h3>Welkom op mijn pagina, vul de gegevens in om mijn motivatiebrief te kunnen zien.</h3>
<form class="formulier-gegevens" name="form" action="" method="post">
<input type="text" name="voornaam" class="formulier-input" placeholder="Vul uw voornaam in" required>
<input type="text" name="tussenvoegsels" class="formulier-input" placeholder="Vul uw tussenvoegsel(s) in">
<input type="text" name="achternaam" class="formulier-input" placeholder="Vul uw achternaam in" required>
<button class="verzend btn btn-lg btn-primary btn-block" type="submit">Verstuur</button>
</form>
</section>

<section id="brief">
<h3>Hier komt de motivatiebrief </h3>
<?php
$voornaam = $_POST['voornaam'];
$tussenvoegsels = $_POST['tussenvoegsels'];
$achternaam = $_POST['achternaam'];

echo $voornaam;
?>
</section>


This is what I have till now, but when the user submits, the
echo
is not shown. How can I accomplish this the easy way?

P.s. I want to use PHP and not JavaScript.

Answer

Your code seems fine. First check if you are saving the file with a php extension. Then start the php file with

<?php 
    //save the variables from POST
?>
 <html><head></head>
 <body>
      Put your html here and when you need to call the variables from php just write the following 

<?php echo htmlentities($voornaam, ENT_QUOTES, 'utf-8'); ?>

  </body></html>

You should always start a php file with php tags.

If this does not solve the problem check if php is active and installed properly with

<?php phpinfo(); ?>

at the start of a php file.

Comments