centrinok
centrinok

Reputation: 298

How to use php to output details of a form from HTML5

<form id="superheroForm" action="submit.php" method="post">
<p><i>Please complete the form. Mandatory fields are marked with a </i><em>*</em></p>
<fieldset>
        <legend>Contact Details</legend><br>
  <label for="Name">Name <em>*</em></label>
  <input id="name" name="name" placeholder="Jane "  autofocus required><br>
  <label for="telephone">Telephone <em>*</em></label>
  <input id="telephone" placeholder="(xxx) xxx-xxxx" title="must be in the following format (xxx)-xxx-xxxx" 
  pattern=[0-9]{3}-[0-9]{3}-[0-9]{4} required><br>
  <label for="email">Email <em>*</em></label>
  <input id="email" type="email" required><br><br>
  </fieldset>

</form>

I have another file named submit.php. Once the user clicks on submit application button, I am supposed to get the php response something like this:
Thanks for submitting your form
Name:
Telephone:

So far I have tried this directly in a new file named submit.php but it doesn't work at all: This is my php code:

<html>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</html>
</body>

Update:Solution: Sorry I did not install PHP the right way.

Upvotes: 0

Views: 62

Answers (2)

夢のの夢
夢のの夢

Reputation: 5846

your php code should contain something like this

<?php
   $name = $_POST['name'];
//then just echo them
   echo $name;
?>

Upvotes: 1

anuraj
anuraj

Reputation: 157

Change your superhero form like this..

<form id="superheroForm" action="submit.php" method="post">
<p><i>Please complete the form. Mandatory fields are marked with a </i><em>*</em></p>
<fieldset>
    <legend>Contact Details</legend><br>
<label for="Name">Name <em>*</em></label>
<input type="text" id="name" name="name" placeholder="Jane "  autofocus required>  <br>
<label for="telephone">Telephone <em>*</em></label>
<input id="telephone"  placeholder="(xxx) xxx-xxxx" name="tel" required><br>
<label for="email">Email <em>*</em></label>
<input id="email" type="email" required><br><br>
</fieldset>

</form>

and Your submit.php is like this

<?php
   if(isset($_POST['name'])){
      echo "Thanks for submitting your form ";
      echo "Name:".$_POST['name'];
      echo "Telephone:".$_POST['tel'];
    }
?>

This is it.

Upvotes: 0

Related Questions