Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

geoffrey
geoffrey
28,724 Points

Adding contact form step: Submission forms

Hello there, there is something I can't figure out on my own with the submissions forms.

I understand everything correctly till now, but there is something boring me.

That's the fact the form doesn't check really if the inputs are empty or not, so even if I don't fill in inputs, If I click the submit button, I get the "thank you message", telling the message was well received and etc...

Shouldn't we have a message telling instead to fill each inputs if ever some information are missing, this before submiting ?

That would probably means others conditions to check each input... at least I guess.

If anyone could help enlight me on this. Thank you...

2 Answers

Sebastian Limbach
Sebastian Limbach
1,536 Points

To check if the inputs are empty you could write a little bit of JavaScript to hide and show the submit button for example. Here is an example code:

$(document).ready(function(){
  $('input[type=text]').on("keyup", function(){
    var inputVal = $('input[type=text]').val();
    if(inputVal !== ""){
      $('input[type=submit]').show();
    }else{
      $('input[type=submit]').hide();
    }
  });
}); 

And here the working example on CodePen. Hope i could help.

Oh and in PHP it would be something like:

if($_POST['text'] == ""){
echo "No input";
}
geoffrey
geoffrey
28,724 Points

Thank you for your answer, nevertheless, after "googling" about that, I think that we have to check it with the isset() function. Moreover, I've just noticed, the teacher enhances the form in the following videos and check each input. My fault, I want to go to too fast !

Anyway, thank you again Sebastian.