Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating form input in PHP
    primarykey
    data
    text
    <p>is it possible to write a PHP page say form.php with a php function generalValidate($form) that is able to perform the following scenario :</p> <ol> <li>user browse to form.php</li> <li>user gets an html form </li> <li>user fills form and the form is sent back with POST method to form.php</li> <li>form.php activate generalValidate($form) where form is the just recived form filled by user</li> <li>generalValidate($form) returns true if this form is valid (for exemple properly filled), false else.</li> </ol> <p>i think that another way to describe my question will be - is there a general way to iterate over an HTML form sent by a client (perhaps a form that the php page itself sent to client in the first place) while activating some code over each of the form values?</p> <p>dont eat me if its a bad question, im really just trying to learn :)</p> <p>a code exemple to fill for your convinience :</p> <pre><code>&lt;?php function generalValidate($form) { ... } if (!isset($_SESSION)) session_start(); else if (generalValidate(...)) { } ?&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;div&gt; &lt;p&gt;Register&lt;/p&gt; &lt;/div&gt; &lt;form id="regfrm" action="&lt;?php echo $_SERVER["PHP_SELF"]; ?&gt;" method="post" align="center"&gt; &lt;table align="center"&gt; &lt;tr&gt; &lt;td&gt;First Name :&lt;/td&gt; &lt;td&gt;&lt;input name="fname" value="&lt;?php if (isset($_POST["fname"])) {echo v($_POST["fname"]);}?&gt;" required&gt;&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Last Name :&lt;/td&gt; &lt;td&gt;&lt;input name="lname" value="&lt;?php if (isset($_POST["lname"])) {echo v($_POST["lname"]);}?&gt;" required&gt;&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Email :&lt;/td&gt; &lt;td&gt;&lt;input id="email" name="email" value="&lt;?php if (isset($_POST["email"])) {echo v($_POST["email"]);} else {echo "xo@xo.xo";}?&gt;" required&gt;&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password :&lt;/td&gt; &lt;td&gt;&lt;input name="pw" type="password" value="e" required&gt;&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Retype password :&lt;/td&gt; &lt;td&gt;&lt;input name="pw" type="password" value="e" required&gt;&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" value="Register" &gt;&lt;/input&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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