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 trialHadi Farhat
10,678 PointsWhy 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
25,698 PointsHi 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.
Niki