|
Posted by Jason Barnett on 05/13/05 23:39
Dan wrote:
> Richard Lynch wrote:
....
>> The "value added" of the central switch seems dubious to me.
>>
>> Just my opinion.
>>
>
> Richard -
>
> I want your opinion, which is why I'm taking a stab at the list ;)
>
> What other methods would be good to use? Using a giant if statement?
>
> Thanks
> -dant
Nononono.... a giant "if" statement is still a case of you trying to
control all form processing in one centralized location. I won't
venture a guess as to why Richard doesn't approve of the centralized
approach, but rather just pointing out that if() is logically similar to
switch().
Now going back to your original question... one easy to predict problem
is that you've forgotten to handle form submission errors. I mean
surely you will want to validate the incoming data and do something
sensible if the data doesn't match some regular expression(s). If
you're really trying to go for a centralized approach then I'd say this
validation should be handled through this main script.
A simple alternative? Each form has its "target" attribute set to
itself. You start out with invalid data. Then when the form POSTs to
itself you can validate the incoming data within the same script where
the form elements are located. This approach puts all of the business
logic for one page *inside the one page*. It makes debugging a lot
simpler because, well, if you have a problem with page1.php then you
know it lies somewhere in the script page1.php instead of any of the
following:
- page1.php
- controller.php
- index.php
- page2.php
- etc.
One of the easiest ways to reduce maintenance is to make it easy to find
your bugs. I'm not being condescending to you, because we all have
bugs. But it sure is easier to fix them when you can find them. :)
Navigation:
[Reply to this message]
|