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
| <?php | |
| //define validation rules | |
| $valRules = array( | |
| "username" => array( | |
| ["R", "Your username is required"] | |
| ), | |
| "email" => array( | |
| ["R", "Your Email is required"], | |
| ["EMAIL", "Your Email is invalid"] | |
| ), |
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
| <?php | |
| //syntax for defining validation rules | |
| $valRules = array( | |
| "FORM_INPUT_NAME" => array( | |
| ["RULE_TITLE", "CUSTOM_ERROR_MESSAGE"] | |
| ) | |
| ); | |
| ?> |
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
| <?php | |
| //include the validation file | |
| require 'octaValidate-php/src/Validate.php'; | |
| use Validate\octaValidate; | |
| //create new instance of the class | |
| $DemoForm = new octaValidate('form_demo'); | |
| ?> |
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> | |
| <body> | |
| <form id="form_demo" method="post" novalidate> | |
| <label>Username</label><br> | |
| <input name="username" type="text" id="inp_uname"> <br> | |
| <label>Email</label><br> | |
| <input name="email" type="email" id="inp_email"> <br> | |
| <label>Age</label><br> | |
| <input name="age" type="number" id="inp_age"> <br> |
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
| //store required extensions | |
| const requiredExts = [".png", ".jpg", ".jpeg"]; | |
| //store error | |
| const valError = []; | |
| //loop through object | |
| for (let file of fileInpFiles){ | |
| //retrieve extension from name | |
| const ext = file.name.substring(file.name.lastIndexOf('.')); | |
| //check if it matches with the required extension | |
| if ( !requiredExts.includes( ext ) ){ |
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
| //create an array that will store the image file type | |
| const requiredTypes = ["image/jpg", "image/jpeg", "image/png"]; | |
| //store error | |
| const valError = []; | |
| //loop through object and compare type | |
| for (let file of fileInpFiles){ | |
| if ( !requiredTypes.includes( file.type ) ){ | |
| valError.push(file.name); | |
| } | |
| } |
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
| //convert 2mb to bytes | |
| const requiredSize = 1024 * 1024 * 2; | |
| //save file size | |
| let filesSize = 0; | |
| //loop through object | |
| for (let file of fileInpFiles){ | |
| //add up file sizes | |
| filesSize+=file.size; | |
| } | |
| //check if files size is greater than 2MB or 2,000,000 bytes |
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
| //loop through object | |
| for (let file of fileInpFiles){ | |
| //log current file | |
| console.log(file); | |
| } |
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
| //retrieve file input element | |
| const fileInp = document.querySelector('#inp_file'); | |
| //retrieve file | |
| const fileInpFiles = fileInp.files | |
| //log result | |
| console.log(fileInpFiles); |
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
| <form novalidate> | |
| <input type="file" id="inp_file" accept=".png" multiple><br><br> | |
| <button type="submit">Upload</button> | |
| <form> |