|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Fri May 30, 2008 2:54 pm Post subject: |
|
|
And forgot to say, your documentation is full of mistakes !
The basic syntax of the {validate ...} function is as follows:
{validate field="foo" criteria="isNumber" message="foo must be a number"}
Those are the three required attributes to a {validate ...}
function call. "field" is the form field the validation will
validate, "criteria" is the validation criteria, and "message" is
the message that will be displayed when an error occurs.
what the heck is " Those are the three required attributes to a {validate ...}"
why is these 2 required : field="foo" criteria="isNumber"
I dont use them, i just use id=""
You DIDNT tell us when to use what, what is the point of this kind of documentation ? where you just give out examples without explaining what is going on ? huh ? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri May 30, 2008 7:24 pm Post subject: |
|
|
If you were paying for help, that would be different. But your attitude sucks. You are making it very difficult for me to even want to lift a finger to help you. Don't bite the hand that feeds you.
Last edited by mohrt on Fri May 30, 2008 7:32 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri May 30, 2008 7:31 pm Post subject: |
|
|
The field and criteria params are the old validation method (which can still be used), but you only need id of the registered criteria and message as you are doing. I'll get that paragraph updated in the docs.
As for $vaue $empty $param and $formvars, they are explained in this paragraph of the docs:
Quote: | Your criteria functions must contain the four parameters given in the
example above. The first parameter is the form field value being validated.
The second is the boolean "empty" value given as a parameter to the
validator (or false if none was given). $params contains all the parameters
passed to the validator, and $formavars contains all the form information.
The last two are passed by reference so you can edit the original values if
need be. |
As for two text-field validation, the "isEqual" validator should work out of the box, otherwise create your own validator and compare the two values from the $value and $formvars information. |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Sat May 31, 2008 7:50 am Post subject: |
|
|
sorry for my rudeness
but you done understand what I am doing.
I said, I done want to compare 2 fields by isequal.
I said above , I have a function, in which, one parameter is taken from form and other from user.
and i NEVER asked you to suggest me to make a new function, I already made one.
I asked what should be the parameters given to register_validator ( if you can read my above posts )
what the heck is this :
$params contains all the parameters passed to the validator
and $formavars contains all the form information.
$params contains what?
I know $formvars contains all the input data of the form.
but what is $params then?
and if both of above have form info, then what is this :
"The first parameter is the form field value being validated". ??
$value ? what is in it ?
If my function is :
Code: | function checkrecip($value, $empty (useless thing to write), $params, $formvars)
{
if ($parameter_one_taken_from_form == $second_param_taken_from_user)
{
echo 'exist';
}
} |
what should I write in register_validator ??
SmartyValidate::register_validator('v_recip', 'user_input_field', 'isRecip');
this one doesnt work !!!
i just want one input from user, other is taken when function is called ( from database)
like :
Code: |
checkrecip ($input_by_form, $taken_from_db);
|
Can you now help me sir ?
Sorry again for my rudeness |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat May 31, 2008 2:39 pm Post subject: |
|
|
$params are passed in with the field name separated by a colon. Example:
Code: | SmartyValidate::register_validator('v_username','username:3:10','isLength'); |
In the above example, $params['field2'] = 3, $params['field3'] = 10.
$value is the value of the field being validated. In the above example, it would be the value of $_POST['username']. (You could also get this from $formvars if you wanted to.)
For your function to compare a database value against a form value, you might do something like the example in the docs:
Code: | function smarty_validate_criteria_isValidPassword($value, $empty, &$params, &$formvars) {
if(strlen($value) == 0)
return $empty;
// we might have a function we call to test the password
// against a database
return is_valid_password($formvars['username'], $value);
}
|
As with all criteria functions, the return value (boolean) determines if the validator passes or fails. In the above example, we have a function is_valid_password() that is used to compare the values. It is up to you to make your database connection and query in that function (or object method, whatever you use.) Ultimately, the validator function needs to return true or false.
I would suggest you take a look at some of the existing plugins, see how they handle $params and $value, etc. |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Mon Jun 02, 2008 5:31 am Post subject: |
|
|
maybe you are forgetting the usage of your own great plugin.
according to your statement above:
Quote: |
$value is the value of the field being validated. In the above example, it would be the value of $_POST['username']. (You could also get this from $formvars if you wanted to.) |
$formvars and $value contains same value, right? thats what you said above, $value is value of field being validated, in this case, it would be $_POST['username'] and you said I could also use $formvars['username'] instead of $value, but then, whats the point of making 2 arguments? if they both have same data, then why the hell we are using 2 of them instead of one of them ?
and to the point now, you said, to compare to my sql, I could use like this :
return is_valid_password($formvars['username'], $value);
but again according to you, $value and formvars['username'] have same data... then how can it possibly take data from my sql ?? :s
I cant understand, its so confusing...
Please help me sir.. I really need this last thing done.. then everything will be just fine.. |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Mon Jun 02, 2008 5:54 am Post subject: |
|
|
I think it should be :
return is_valid_password($params['field'], $params['field2']);
And this is certainly it, but I am having another problem with it.
during validation, it is breaking my link
my bit of code :
Code: | $test = new test;
$recip = $test -> recip;
class test {
var $recip = 'http://www.bilalghouri.com/';
function init($value, $empty, &$params, &$formvars)
{
print_r($params);
return say($params['field'], $params['field2']);
}
....another function....
}
SmartyValidate::connect($smarty, true);
SmartyValidate::register_object('test', $test);
SmartyValidate::register_criteria('Say','test->init');
SmartyValidate::register_validator('v_say',"say:$recip",'Say', false, false, 'trim'); |
using print_r I get this :
Code: |
Array ( [field] => say [field2] => http [field3] => //www.bilalghouri.com/ [id] => v_say [criteria] => Say [message] => asdasdasdasdasd [trim] => [empty] => [halt] => [transform] => trim ) |
see ? its breaking the variable into 2 fields, http and //www.bilalghouri.com/
its taking : between the 2 strings as a 3rd parameter
please help |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 02, 2008 2:39 pm Post subject: |
|
|
The value you pass must be a field name, not a string such as a URL.
So maybe go with something like:
SmartyValidate::register_validator('v_say',"say:recip",'Say', false, false, 'trim');
And in your form, $_POST['recip'] = 'http://www.bilalghouri.com/'
Then inside the validator, you could get that value with $formvars[$param[$field2]]
Quote: | $formvars and $value contains same value, right? |
No. $formvars contains ALL of the POST vars. $value contains the value of the current field being validated. $value is also part of the POST vars, so it will be visible in $formvars. $value is there for your convenience. |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Tue Jun 03, 2008 9:09 am Post subject: |
|
|
why dont u listen before replying?
didnt I say that second argument is taken from db.
then where did a $_POST['recip'] come from ? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 03, 2008 3:11 pm Post subject: |
|
|
Why don't you read everything before throwing accusations? I'm done with this one. Everything you need to create custom validators is in the docs. As for grabbing values from mysql, that is up to you, but you can easily do that in a validator.
Bottom line, your validator must return true or false (boolean). All the post values are available in the validator. The value of the current field is available in $value. Any extra field names are passed in as params. You can compare anything you want to a db value from there.
Why don't you take a look at existing validators, and then try to build one yourself and DEBUG the values that come into the validator.
And, it doesn't help to throw insults at people you are trying to get help from. You are on your own, good luck. |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Tue Jun 17, 2008 12:55 pm Post subject: |
|
|
Ah, I give up
Thanks for the help though..
You were really very helpful, but I used other way to validate the reciprocal, i made some changes in my existing class, so it worked now.
You were really helpful, I used your suggestion ($fomvars) and it worked.
Thanks for help again |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Tue Jun 17, 2008 12:59 pm Post subject: |
|
|
and yeah, i forgot to say sorry to you.
I am really sorry for my rudeness.
I am such a short tempered boy( yeah , Im 15 yrs old)
I apologize for my rudeness, Thank you for your help, please forgive me if possible |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|