Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...
Facebook: / youaccel
Twitter: / youaccel
Website: http://youaccel.com
Tutorial Content:
In this lesson, we are going to add additional validation to our form. We're going to make it so that users must fill in their Name and Website in order to submit the form. If they leave the fields empty, an error message will be displayed. To do this we will be using the empty() function.
So let's get started.
Our error messages will be displayed in red, so first, let's create a style sheet with one class called error. Create a color definition set to red.
Now we can create our validation. We need the validation statements to execute as soon as the form is submitted. We also want the data outputted, only if the required fields are completed.
We can do this by creating an if statement and using the empty() function to check if certain fields are empty. In this case, the Name and Website field.
Insert the following code, directly below your first if statement.
Remember to close your new if statement, otherwise you will get an error.
In this block of code, we have stated that if there is no value inputted in the Name field, to output an error stating that the First Name is required.
If the First Name is not empty, then it will check for the Website field. If the Website is left empty, similarly an error will appear, stating the Website is required.
If both fields are not empty, the code block after the else statement will execute. Meaning the input data will be outputted on our page.
In questa pagina del sito puoi guardare il video online PHP Form Required Fields | Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato YouAccel 09 maggio 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 474 volte e gli è piaciuto 2 spettatori. Buona visione!