This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //syntax | |
| checkFormFields(fields_array, return); | |
| //call the function | |
| $fields = [ | |
| "fname" => "First Name", | |
| "lname" => "Last Name", | |
| "email" => "Email Address" | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (checkFormFields($fields, true) == 1) { | |
| echo "one or more fields are empty"; | |
| } else { | |
| echo "No field is empty"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function checkFormFields($fields, $return) { | |
| $requiredFields = []; //init required fields var | |
| $emptyFields = array(); //init empty fields var | |
| foreach ($fields as $field=>$fieldTag) //loop through the array to find the fields and field tags associated | |
| { | |
| array_push($requiredFields, $field); //push required field to the array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <form method="post"> | |
| <input name="fname"> <br> | |
| <input name="lname"> <br> | |
| <input name="email"> <br> | |
| <button type="submit">Submit</button> | |
| </form> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ($_POST){ | |
| $fields = [ | |
| "fname" => "First Name", | |
| "lname" => "Last Name", | |
| "email" => "Email" | |
| ]; | |
| //call the function | |
| if (checkFormFields($fields, false) == 1) { |
OlderNewer