Reputation: 23
i have been trying to get my filled out form to display next to it. I have tried doing this with an if statement but no luck.
I also trying just doing print_r and that did work but i want it to be after u hit submit it shows.
heres my code so far!
<form action="phptest1.php" method="POST">
<fieldset>
<legend>Inloggegevens:</legend>
<label for="naam">Gebruikersnaam:</label>
<input type="text" name="naam" id="naam">
<label for="wachtwoord">Wachtwoord:</label>
<input type="password" name="wachtwoord" id="wachtwoord"><br>
<label for="man">Man</label><br>
<input type="radio" name="gender" value="male"><br>
<label for="for">Vrouw</label><br>
<input type="radio" name="gender" value="female"><br>
<label for="checkbox">Ik heb de algemene voorwaarden gelezen.</label><br>
<input type="checkbox" name="conditions" value="agree">
<textarea name="commentaar" rows="4" cols="40"
placeholder="Schrijf hier uw commentaar…"></textarea>
<select name="land">
<option value="nl">Nederland</option>
<option value="be">België</option>
<option value="de">Duitsland</option>
<option value="fr">Frankrijk</option>
</select>
</fieldset>
<input type="reset"><br>
<input for="submit" type="submit">
<?php
if (isset($_POST['submit']))
{
echo '<h1>'.$_POST['naam'].'</h1>';
echo '<br><br>';
echo $_POST['wachtwoord'];
echo '<br><br>';
echo $_POST["gender"];
echo '<br><br>';
echo $_POST["land"];
echo '<br><br>';
} else {
echo 'U bent nog niet ingelogd.';
}
?>
Upvotes: 0
Views: 50
Reputation: 154
Replace your submit button with the following :
<input type="submit" name="submit" value="submit"/>
And make sure the post is submitted to the same page by removing phptest1.php from action or just use:
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
Upvotes: 0
Reputation: 5224
The indices of $_POST
are populated by the name of the input
elements. Since you have no element named submit
your isset
is never met. To fix that give it a name.
<input for="submit" type="submit" name="submit">
Upvotes: 2
Reputation: 7661
Instead of
action="phptest.php"
if(isset($_POST['submit']))
You can just use
action=""
if($_POST)
The action=""
will make sure the post is send to the current page/ file again.
The if($_POST)
still makes sure that the code inside the if
statement is only run when the page is posted. You could use isset($_POST['submit'])
however your submit button doesn't have a name of submit
so there will never be a $_POST['submit']
.
Upvotes: 0