Ok, To summarise your requirements: 1. No javascript validation (users must reload for any validation). 2. No information on which field is missing. 3. Same message on all forms in all cases. 4. Simplest possible syntax for html designers who set the required fields.
Possible syntaxes: a) Set hidden required field on form e.g. <INPUT TYPE="HIDDEN" NAME="REQUIRED" VALUE="name,address,phone"> b) Set variable in php e.g. $required = 'name address phone'; $required = 'name,address,phone'; $required = array($name,$address,$phone); c) Call function in php e.g. required('name address phone'); required('name,address,phone'); required($name,$address,$phone); $required = 'a b'; $required = 'a,b'; $required = array($a,$b); $required = a b ; //required(a b); required(a,b); ho handles the Javascript on-page validation? Or do you always force your users to wait for a page reload before telling them about simple errors? The Javascript is Brandon Lamb wrote: > > The point of keeping it easier is what if i want to give my script to a > friend, do you REALLY want to explain to a non-programmer how to add another > if statement or condition when they could simply add the field to the array? > > And actually you only have to change the name in 2 places. > 1. you define the variable as an input from a form > 2. in the required fields array > > ----- Original Message ----- > From: "George Whiffen" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Wednesday, November 21, 2001 7:28 AM > Subject: Re: [PHP] How do I convert from perl to php? - Reality Check & > Taxation > > > So I would have to write a seperate if condition for each form input field > i wanted to require? that doesn't make for a very dynamic script... > > > > > if(!(isset($name) && isset($address) && isset($phone)) { > > > echo "You left one empty."; > > > } > > Reality Check: We write code to solve real world problems! > > The parts of our code which are essential to the describe the real world > problem we want solved are > essential. All the rest of our code is an unfortunate "tax" on the rest of > the world. The code can > be as complex, dynamic, interesting or clever as it likes, it's still tax! > "Very dynamic script"s > have to be JUSTIFIED, they are not, repeat not, intrinsically good! > > In this case, the essential elements are the names of the fields required > and the message to be sent > if they are not present i.e. the following 38 characters > > "name address phone You left one empty." > > Rasmus code consists of 92 characters i.e. 44 extra characters or around > 110% tax. Does that sound > a lot? Your original perl had 192 characters i.e. over 400% tax. > > What about maintainability/reusability? Lets look at the tax element of > some likely changes: > > 1. Change in the name of one of the required fields e.g. name should now be > lastname > Rasmus : 0% TAX: (You change "name" to "lastname" once) > Perl : 200% TAX: (You change "name" to "lastname" in 3 places) > > 2. Remove one of the fields from the required list > Rasmus : 12 characters TAX (You have to remove "&& isset($) " as well as the > field name itself) > Perl : 13 characters + 200% TAX (You must remove "$ = param($);\n" and the > field name 3 times) > > 3. Add a new field > As per 2. above. > > 4. Modify the conditions for the error message e.g. change to name and > either address or phone > required > Rasmus : 4 characters TAX (change && to "or" and add two brackets) i.e. > if(!(isset($name) && (isset($address) or isset($phone)) { > Perl : Rewrite required....unknown cost! > > Well, I hope that resolves the question of which is the more world-friendly > code (i.e. more "tax" > efficient). > > Personally, and all views on simplicity, elegance and beauty of code are > subjective, I also find > Rasums php version much simpler and easier to understand. It involves far > fewer commands and is > therefore much more accessible to the novice programmer. It has much less > extraneous structure and > is clearly focussed on the task in hand. It can very easily be extended and > modified to provide > richer functionality. What more do we want? (Well personally, I'd rather he > used "and" instead of > "&&" and "not" instead of "!" and put the separate conditions on separate > lines and generally had > more white space ;). > > George > > P.S. Is this a characteristic example of the difference beteeen Perl and > PHP or an extreme > example? Is Perl really so "geeky" in style and application? Or am I just > too stupid, stubborn, > ignorant to see that Perl is better than php? > > [EMAIL PROTECTED] wrote: > > > > So I would have to write a seperate if condition for each form input field > i wanted to require? that doesn't make for a very dynamic script... > > > > > if(!(isset($name) && isset($address) && isset($phone)) { > > > echo "You left one empty."; > > > } > > > > > > On Tue, 20 Nov 2001 [EMAIL PROTECTED] wrote: > > > > > > > I am a perl user trying to convert to php > > > > > > > > how would i turn this perl into php? > > > > > > > > use CGI; > > > > > > > > $name = param(name); > > > > $address = param(address); > > > > $phone = param(phone); > > > > > > > > @required = qw( name address phone ); > > > > > > > > foreach $key($required) > > > > { > > > > if (!$$key) { &out("You left one empty."); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]