I've created a jQuery form that people can fill in. When they're finished, they can click one of two buttons to post the form to a PHP file. The PHP file processes the data in the form and put it into the database. The database then has some triggers, and the data is output.
What I'm wondering is if I should submit to the same PHP file regardless of which button they press and just use conditional statements inside the PHP file? Or is it cool if I use a different PHP file: one for either button?
I'm also using the PHP wordwrap()
function with <br>
as an argument. I'm wondering if I should just be using CSS to word wrap because it may cause problems with handling the data form within MySQL.
If the logic triggered by the two buttons is largely similar, then a single script makes sense - you only have to special-case whatever minor bits are different between the two.
If the two logic paths are fundamentally different, then it may make more sense to have two separate scripts. The choice is up to you.
As for wordwrap, generally you should alway store data in its "raw" format, and only do such processing upon retrieval for display. This is especially true if the data will be used in multiple output formats: plain text, html, pdf, excel, etc... Each has its own word wrapping rules/requirements, and forcing your data to be stored in html-style means you'd just have to undo all that work when dealing with one of the other targets.
Six of one, half dozen of the other on the method. I personally progressively enhance my forms to use Ajax submission to an "AjaxDispatcher" that processes ALL form submissions, but that's entirely preference.
With the PHP, be thinking about the worst case scenario--if someone gets some bad info through or the DB fails, how am I going to tell them of the problem? That's why I use the Ajax method, with built-in return methods for easy notification. It can be done server side too to avoid ajax, it's just not as quick for the user or pretty.
Definitely don't forget the form pre-processing, which is made much easier via jQuery inline validation It makes for more user-friendly feedback about form issues and doesn't "cost" a php hit in the process. It's not a replacement for server-side validation, but a nice added touch.
I would question the need for two buttons. I do UI development in online applications for a living and a recent site "dictated" that we do two buttons for relatively similar paths because the marketing types couldn't understand how similar the paths were. It turned into a giant mess, with multiple different "paths" through the process that just confused the living daylights out of the site's users. Never mind that it resulted in having to write a test routine that had 14 different cases (don't ask!) Depending on your situation, you can draw from hidden fields, combinations of answers, or other methods to achieve a form with just one simple input, which is much more user friendly in the grand scheme of things. It also makes it an easier decision on your part as to how to process the data.
When in doubt, remember that the art of UI is simply making an unfamiliar situation feel familiar to the user despite never having been there before. Now, how many forms have you filled out recently with two different methods to submit, side-by-side?
I wouldn't personally wordwrap a textarea. It could have some unexpected consequences if the user starts resizing your textareas as most modern browsers now allow. HTML actually handles wrapping relatively gracefully, considering it's just markup.