Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>&lt;?php // to eventually re-fill the fields $name = ""; $email = ""; $gender = ""; $age = ""; $comments = ""; // to re-select a radio button and select option $Mchecked = ""; $Fchecked = ""; $selectMinus_30=""; $select30_to_60=""; $select60_plus=""; // to display errors $error = ""; $done=false; if (isset($_POST["name"]) &amp;&amp; isset($_POST["email"]) &amp;&amp; isset($_POST["age"])){ if($_POST["name"]==""){ $error = "empty name &lt;br/&gt;"; } if($_POST["email"]==""){ $error = $error . "empty mail &lt;br/&gt;"; } if(!isset($_POST["gen"])){ $error = $error . "empty gender &lt;br/&gt;"; } else{ $gender = $_POST["gen"]; if ($gender == "Male"){ $Mchecked = "checked"; } else if ($gender == "Female"){ $Fchecked = "checked"; } } if($_POST["comments"]==""){ $error = $error . "error: empty comments &lt;br/&gt;"; } $name = $_POST["name"]; $email = $_POST["email"]; $comments = $_POST["comments"]; $age = $_POST["age"]; if ($age == "Under 30"){ $selectMinus_30 = "selected"; } else if ($age == "Between 30 and 60"){ $select30_to_60 = "selected"; } else if ($age == "60+"){ $select60_plus = "selected"; } if ($error==""){ $done=true; } } ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Lab6 : P1&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if (!$done){ ?&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;h4&gt;Enter your information in the fields below&lt;/h4&gt;&lt;/legend&gt; &lt;p class="error" style="color:red;"&gt;&lt;?php echo $error;?&gt;&lt;/p&gt; &lt;form name="info" method="post" action="&lt;?php echo $_SERVER["PHP_SELF"];?&gt;" method="post"&gt; &lt;strong&gt;Name:&lt;/strong&gt; &lt;input type="text" name="name" id="name" value="&lt;?php echo $name; ?&gt;" /&gt;&lt;br/&gt; &lt;strong&gt;Email:&lt;/strong&gt; &lt;input type="text" name="email" id="email" value="&lt;?php echo $email; ?&gt;" /&gt;&lt;br/&gt; &lt;br/&gt; &lt;strong&gt;Gender&lt;/strong&gt;&lt;br/&gt; &lt;input type="radio" name="gen" value="Male" &lt;?php echo $Mchecked;?&gt;&gt;Male&lt;/input&gt;&lt;br/&gt; &lt;input type="radio" name="gen" value="Female" &lt;?php echo $Fchecked;?&gt;&gt;Female&lt;/input&gt;&lt;br/&gt; &lt;br/&gt; &lt;select name="age" value="&lt;?php echo $age;?&gt;"&gt; &lt;option value="Under 30" &lt;?php echo $selectMinus_30;?&gt;&gt;Under 30&lt;/option&gt;&lt;br/&gt; &lt;option value="Between 30 and 60" &lt;?php echo $select30_to_60;?&gt;&gt;Between 30 and 60&lt;/option&gt;&lt;br/&gt; &lt;option value="60+" &lt;?php echo $select60_plus;?&gt;&gt;60+&lt;/option&gt; &lt;/select&gt; &lt;br/&gt; Comments: &lt;textarea name="comments" cols="20" rows="5"&gt;&lt;?php echo $comments; ?&gt;&lt;/textarea&gt; &lt;/fieldset&gt; &lt;input type="submit" name="submit" value="Submit my Information" /&gt; &lt;/form&gt; &lt;?php }else{ echo "Thank you, ".$name." for your comments: " . "&lt;strong&gt;" . $comments . "&lt;/strong&gt;"; echo "&lt;br/&gt;We will reply to you at:" . "&lt;em&gt;" . $email . "&lt;/em&gt;"; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here I did proper validation, and also re-fill the form when you submit with any empty field.<br/></p> <hr> <p>P.S. Thank you Marc B , I didn't realize that my first post was aweful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload