Page 1 of 1
submitting forms to themselves
Posted: Sun Aug 24, 2003 10:52 am
by benedict5980
Hi everyone,
I'm new to PHP and I want to start coding the right way if possible.
I've seen codes wherein a form is submitted to itself('PHP_SELF'). I was wondering about which is better: submitting a form to itself or submitting to another file?
Your insights on this will be most appreciated. Thanks in advance!

Posted: Sun Aug 24, 2003 11:46 am
by RFairey
Self submission means all your code is in one file, instead of in two, the HTML form and the handling code.
Posted: Sun Aug 24, 2003 8:14 pm
by benedict5980
Exactly RFairey!
I want know which is better? Is one method better than the other?

Posted: Sun Aug 24, 2003 8:45 pm
by volka
if there's no framework telling me otherwise I like to keep the code of view(s) and controller of a component as near together as possible. But that's still open to debate

Posted: Sun Aug 24, 2003 9:08 pm
by brewmiser
I would think that it would have to do with your preference. It would seem that you have a choice of dealing with only a couple of large files with everything in it, or breaking it up into smaller files, but having to remember which file it was in.
Posted: Sun Aug 24, 2003 9:36 pm
by benedict5980
But performance wise? Is there a difference between the two? Which is faster?
Posted: Sun Aug 24, 2003 9:46 pm
by jason
Neither is really faster. The act of submitting the form is the same, and the speed is the same. The fact that you have both form display and form handling stuff in the same file "could possible maybe" have a chance of slowing the script down every so slightly at the smallest level depending on how you structure your code.
So the answer is No. It won't slow anything down. Using the MVC style is pretty much going to set up the fact that you will use the same page anyways, so all is on your side.
Posted: Sun Aug 24, 2003 10:12 pm
by benedict5980
I see now. Thanks alot! I thought one was better than the other. Thanks again!

Posted: Mon Aug 25, 2003 12:57 am
by BassPlayer
I use this alot and it's really nice. I also found and idea on the net of using a hidden form element called op. So say I have a script called admin.php which has a bunch o if/elseif statements looking for particular op values.. When admin.php is first run op is "" so it gives the main menu. Once I select something like edit user op becomes edituser and admin.php being the form action is called again. Admin.php walks its if statements and when it gets to edit user it prints the edit user form which has admin.php as the form action. etc etc you get the picture.
Posted: Tue Aug 26, 2003 10:51 am
by m3rajk
which is better? that's hard. personally i prefer one page if you're doing error handling.
easier to repopulate the form since you have one function that does all the display and another that prepends error messages (if any) and a success.. just have a hidden element that tells it whether it's a submission or not.
if you want to see a rather complicated example....
http://24.91.157.113/findyourdesire/join.showcode
Posted: Tue Aug 26, 2003 1:45 pm
by nielsene
I personally prefer to use different pages. I'll have web viewable pages in one directory and processing scripts in another. Yes it means I have to do a little more work to pass values around to pre-populate forms/error messages, however it keeps both files shorter and simpler.
The web displayable files end up just being a series of calls to either my database layer to get content or to my html layer to format it.
The script files use mainly generic utility functions and regexps to validate and then the database layer to transparently handle inserts/updates/delete before passing control back to another vieable file.
At times I'll use the self-submitting page, but I won't use the mutliple forms with processing all in one page paradigm. It is just too ugly in my opinion. Anytime I see a whole application done in one page with switch/if else if... I cringe. That doesn't mean its wrong, others have the same reaction to my design.