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!

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 Build a Basic PHP Website (2018) Adding a Basic Form Checking the Request Method

Hadi Farhat
Hadi Farhat
10,678 Points

Why combine all files into a single one when they were perfectly separated?

Why did you combine the code of thanks.php & process.php into suggest.php?

They were logically separated into 3 files and I, I don't know if this is a bad practice, prefer it this way.

1 Answer

Niki Molnar
Niki Molnar
25,698 Points

Hi Hadi

I've been coding PHP for about 10 years and if it's a complicated form that's being submitted, I sometimes keep all the code on a single page, primarily because of error checking. It's a lot easier to show the form again with the errors, without having to pass all the data back to the form page.

The only time you have to use a separate page is when you are using jQuery/AJAX to submit the form, as the error checking can be done by jQuery before submission but AJAX does require sending the data to another page.

Another reason that I keep it separate is if there's a chance that a user may hit refresh and submit the form again (although you should check for this).

There is no right or wrong though. For years, I've submitted forms to another page and I still think it makes an application tidier and easier to find where something's gone wrong. It does increase the number of files though!

It's personal preference but learn to do both as situations may warrant either.