Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can i make php form? I have three php file. (1) <html> <head> <meta http-equ

ID: 3871111 • Letter: H

Question

How can i make php form?

I have three php file.

(1)

<html>
   
    <head>
   
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
       <title>Form Feedback</title>
   
    </head>
   
    <body>

   
    <?php # MyFirstForm.php
   
   
   
    // Create a shorthand for the form data:
   
    $name = $_REQUEST['name'];
   
    $email = $_REQUEST['email'];
   
    $comments = $_REQUEST['comments'];
   
   
   
    // Create the $gender variable:
   
    if (isset($_REQUEST['gender'])) {
   
       $gender = $_REQUEST['gender'];
   
    } else {
   
       $gender = NULL;
   
    }
   
   
   
    // Print the submitted information:
   
    echo "<p>Thank you, <b>$name</b>, for the following comments:<br />
   
    <tt>$comments</tt></p>
   
    <p>We will reply to you at <i>$email</i>.</p> ";
   
   
   
    // Print a message based upon the gender value:
   
    if ($gender == 'M') {
   
       echo '<p><b>Good day, Sir!</b></p>';
   
    } elseif ($gender == 'F') {
   
       echo '<p><b>Good day, Madam!</b></p>';
   
    } else { // No gender selected.
   
       echo '<p><b>You forgot to enter your gender!</b></p>';
   
    }
   
   
   
    ?>
   
    </body>
   
    </html>

(2)

    <html>
   
    <head>
   
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
       <title>Form Feedback</title>
   
    </head>
   
    <body>
   
    <?php # Script MyFirstForm.php
   
   
   
    // Create a shorthand for the form data:
   
    $name = $_REQUEST['name'];
   
    $email = $_REQUEST['email'];
   
    $comments = $_REQUEST['comments'];
   
   
   
    //$name=$_REQUEST['age'];
   
    //$name=$_REQUEST['gender'];
   
    //$name=$_REQUEST['submit'];
   
   
   
   
   
    // Print the submitted information:
   
    echo "<p>Thank you, <b>$name</b>, for the following comments:<br />
   
    <tt>$comments</tt></p>
   
    <p>We will reply to you at <i>$email</i>.</p> ";
   
   
   
    ?>
   
    </body>
   
    </html>

(3)

   <html>
   
    <head>
   
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
       <title>Form Feedback</title>
   
    </head>
   
    <body>
   
    <?php # Script 2.5 - handle_form_printing.php
   
   
   
    // Print the submitted information:
   
    if ( !empty($_POST['name']) && !empty($_POST['comments']) && !empty($_POST['email']) ) {
   
       echo "<p>Thank you, <b>{$_POST['name']}</b>, for the following comments:<br />
   
    <tt>{$_POST['comments']}</tt></p>
   
    <p>We will reply to you at <i>{$_POST['email']}</i>.</p> ";
   
    } else { // Missing form value.
   
       echo '<p>Please go back and fill out the form again.</p>';
   
    }
   
    ?>
   
    </body>
   
    </html>


Explanation / Answer

according to your code you are trying to create a feedback form with certain validation .

lets make it in a simple way

step1. first we desgin a user interface to take inputs from user for that we need basic html codes. lets name this file

1.feedback_form.php

<html>
   
    <head>
   
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
        <title>Form Feedback</title>
   
    </head>
   
    <body>


   <form action="handle_form_printing.php" method="post" >
       Name:<input type="text" name="name"><br>
       Gender:Male<input type="radio" name="gender" value="M"> &nbsp;
           Female<input type="radio" name="gender" value="F">

<br>
       Age:<input type="text" name="age"><br>
       Email:<input type="text" name="email"><br>
       Comments:<textarea name="comments"></textarea><br>
       <input type="submit" name="sub" value="submit">
          
   </form>   
    </body>
    </html>

Step2. Now make a php script for handling incoming data from the above form and print the data

#handle_form_printing.php

<html>
   
    <head>
   
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
        <title>Form Feedback</title>
   
    </head>
   
    <body>

    <?php

       $name = $_REQUEST['name'];
   
        $email = $_REQUEST['email'];
   
        $comments = $_REQUEST['comments'];
           

       $gender=$_REQUEST['gender'];

           // Print the submitted information:
   
    echo "<p>Thank you, <b>$name</b>, for the following comments:<br />
   
    <tt>$comments</tt></p>
   
    <p>We will reply to you at <i>$email</i>.</p> ";
  
       if ($gender == 'M') {
   
                  echo '<p><b>Good day, Sir!</b></p>';
   
           } elseif ($gender == 'F') {
   
                echo '<p><b>Good day, Madam!</b></p>';
   
       } else { // No gender selected.
   
                  echo '<p><b>You forgot to enter your gender!</b></p>';
   
        }

      
   ?>


  
   
    </body>
   
    </html>

Done!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote