Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGremyko Coleman
9,756 Points"Please fill in the required fields:" error message
For the error message that is displayed in this tutorial, is there anyway to have the error message to echo to the current page with the form, instead of it going to a separate page because of the exit command? Because I don't want to have a user having to press the back button just to go back to the form.
if($name == "" || $email=="" $details == ""){ echo "please fill in the required fields: Name,email,"; exit }
1 Answer
Dennis Amiel Domingo
17,813 PointsI also had the same question. When I researched the web, I stumbled upon $_SERVER[PHP_SELF]. The code is different from what we did in this video but the end result is the same. There are also some functions there that we haven't learned of yet, but a quick php manual check will fill you in on it.
If you really want to have that set up now then check out this link: https://www.w3schools.com/php/showphp.asp?filename=demo_form_validation_special
The example above came from this topic: https://www.w3schools.com/php/php_form_url_email.asp
If you still want to use Alena's set up, I suggest you just add in an attribute called "required" for each input fields.
<tr>
<th><label for="name">Name</label></th>
<td><input type="text" id="name" name="name" required/></td>
</tr>
Gremyko Coleman
9,756 PointsGremyko Coleman
9,756 PointsDennis, Thanks, I needed this because, I wanted the validation of PHP to work just incase the user turns off their JavaScript off on their device.