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 trial

PHP

coskun olcucu
coskun olcucu
5,340 Points

Why it doesn't show form page agin when i only hit the send button without filling out the form?

Hi, I am studying building basic web with php. instructor created a form and showed that redirect the same page after form submission. My question is if I don;t fill out the form and hit the send button,isn't it supposed to the stay on same page without any new message.

because according to the code that she created if you fill out the form it redirects you same page and display "Thank you " message. However,when i don't fill out form and hit the send button it shows "thank you" message. Can you help me about this issue?

3 Answers

Forms do not inherently contain validation. you have to create it. ie - you have to check if the required fields are empty and then either not submit the form or do whatever you're going to do for that condition. without seeing the code there's not much to go on. I guess the answer is, if you didn't write form validation then no, it won't behave how you expect.

also, you can do form validation either before or after the form is submitted, so it's not always an issue of the form submitting or not.

coskun olcucu
coskun olcucu
5,340 Points

hi, That's what i did exactly . First i checked the each form field is whether empty or not.It is working as i want.But instructor didn't show that part,she just fill out the form and redirect the page.

I have other issue is when i fill out the form it redirects me same page with different message that it is supposed to do. But when i hit the backward button on the form,It takes me form page with the form filled already filled.I want to see form page without any field filled.???

hitting the back button and getting the filled out form is a product of the browser. if you absolutely want "back" to take you to an empty form, you could try resetting the form on pageload using javascript, something like:

document.getElementById("formid").reset();

ideally, though, you don't want to depend on the back button. You should provide a link back to the original page on your thank you page that says something like "submit another form" or whatever context specific wording makes sense. you always want to create a way for your users to move forward(not backward) through your site. if you just make the link with an empty href attribute it will refresh the page and give you an empty form.

coskun olcucu
coskun olcucu
5,340 Points

Thank you for your explanation. I will try javascript code on my page.