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.
Nesta página do site você pode assistir ao vídeo on-line PHP Form Required Fields | Tutorial duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário YouAccel 09 Maio 2019, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 474 vezes e gostou 2 espectadores. Boa visualização!