Page 4 of 4

Posted: Wed Feb 22, 2006 3:01 am
by quocbao
f5c31ba3f53a0b351f422cb01ea4dd2c

Well , i want to know what form is submited ( a page can contain many forms ) , so i generate this .
I'm doing a little change to the code to make it clearer :D

Posted: Wed Feb 22, 2006 12:24 pm
by Christopher
quocbao wrote:Well , i want to know what form is submited ( a page can contain many forms ) , so i generate this .
Yes, but the form designer also knows about the multiple forms and can give them more meaningful names.

Posted: Wed Feb 22, 2006 6:37 pm
by quocbao
Well , this is the result . The designer can give him a name using form id
<form id="meaning_name" method=post action="somewhere" validation="client">
And a developer can use

Code: Select all

if (SmartValidator::validate($form,'meaning_name')) //is form meaning_name submitted and its data is valid

Posted: Wed Feb 22, 2006 6:52 pm
by quocbao
And here is it http://diskc.net/smartValidator.rar

It's still a mess :( , don't try to apply it to your real application , because it can mess your HTML Id name Name ( i'm stupid ) , but you can test with it :)
I have written 4 rules so far , you can view it in "rule.txt" , the rule name is clear to understand :D

To enable validation for a form
<form ..... validation="mode">
where mode can be server,client,and both :)

Try it , and tell me what you think ..... about this mess :P

Posted: Thu Feb 23, 2006 1:16 am
by Christopher
quocbao wrote:Try it , and tell me what you think ..... about this mess :P
Well I tried to try it. First, it would be great if you used gzip or zip rather than rar. Then use "<?php" in your files rather than "<?". And don't use pass by reference in smartValidator.php. And put "if (isset(...)) {" checks around your foreach loops.

Even after fixing all of that it didn't print any error messages. Maybe version 2?

Posted: Thu Feb 23, 2006 4:13 am
by quocbao
Here's the zip version : http://diskc.net/smartValidator.zip , :D sorry about rar extension
And don't use pass by reference in smartValidator.php

Code: Select all

function validate(&$data,$id=null,$break=false)
I want to pass by reference , because i want this function only return true / false .
If true then everything is ok , but if false then the form is not submited or data is not valid .
And put "if (isset(...)) {" checks around your foreach loops.
Can you show me this part ?
Even after fixing all of that it didn't print any error messages. Maybe version 2?
I try it on my server and it work :(
http://diskc.net/val/test.php

I'm re-coding it :( , let hope it will be better

Posted: Thu Feb 23, 2006 9:45 am
by feyd
It shouldn't be manipulating the data, I think that's the point arborint is trying to make.

Posted: Thu Feb 23, 2006 12:01 pm
by Christopher
Pass by reference example is this:

Code: Select all

$form_content = $smartValidator->parser_input($f , $form_content,&$server_validation);
Foreach loops should be checked like:

Code: Select all

if (isset($server_validation['name']))
				foreach ($server_validation['name'] as $name => $index)
				{
...
				}
			} else {
// set values for error here
			}
The code still needs normal "<?php" tags to be usable by others.

You might want to show all errors and notices and check the code.

Posted: Thu Feb 23, 2006 7:35 pm
by quocbao
Pass by reference example is this:

Code: Select all

$form_content = $smartValidator->parser_input($f , $form_content,&$server_validation);
As you see , i use reference when a function return more than one value ( this function return new form content and server validation value ) . And i don't have any solution yet but pass by reference.
Foreach loops should be checked like:

Code: Select all

if (isset($server_validation['name']))
				foreach ($server_validation['name'] as $name => $index)
				{
...
				}
			} else {
// set values for error here
			}
:? , yes . I didn't notice that , if the form is empty then there will be some notice error :?
The code still needs normal "<?php" tags to be usable by others.
Sorry about that, i used "<?" when i first programmed PHP , and it's become a habit :oops: .
But why "<?php" ? "<?" is shorter :oops: :P
You might want to show all errors and notices and check the code.
I think you should put all error messages here.It's make easier to know what happen .

Posted: Thu Feb 23, 2006 9:17 pm
by feyd
<?php vs <?

Answer: <?php is portable. Short tags are not.

Posted: Thu Feb 23, 2006 9:24 pm
by Christopher
quocbao wrote:Pass by reference example is this:

Code: Select all

$form_content = $smartValidator->parser_input($f , $form_content,&$server_validation);
As you see , i use reference when a function return more than one value ( this function return new form content and server validation value ) . And i don't have any solution yet but pass by reference.
If you want to pass by reference then specify it in the function, not when you pass the variable to the function. The line above gives a Notice/Warning
quocbao wrote: Sorry about that, i used "<?" when i first programmed PHP , and it's become a habit :oops: .
But why "<?php" ? "<?" is shorter :oops: :P
I can't run the code with default PHP 5.1.2 settings, and had to change them all to '<?php'

Posted: Fri Feb 24, 2006 9:10 am
by quocbao
Thanks about <? vs <?php :)

I used to programing in PHP4 and PHP5.1 , so i didn't notice about that :)