|
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 |
ZuqR Smarty Rookie
Joined: 01 Dec 2007 Posts: 6
|
Posted: Sun Feb 17, 2008 10:44 am Post subject: |
|
|
Would it be possible to see a live demo? |
|
Back to top |
|
newname Smarty Rookie
Joined: 25 May 2008 Posts: 26
|
Posted: Sun May 25, 2008 9:39 am Post subject: |
|
|
first of all.. Thanks for the great plugin.
I didnt really need it, I had my own validation functions..
but I though it would look more professional to use Smarty Validate..
so i am using it now..
But I have many problems regarding it.
First of all, Your Forum Registeration system sucks !!!!!!
i had to register 4 times to get activation email :@
I used live[dot]com email for first try, didnt work.
then used hotmail , didnt work.
Then used mailinator[dot]com, didnt work.
then today on fourth try, i used another mailinator email, and it worked.
but I am so angry I had to use this stupid username :@
Please fix it.
And secondly, Congrats for this Awesome plugin
now, to my point.
I was trying to register for 3 days to get this problem fixed
Here is my bit of smarty code :
Code: | if (empty($_POST['submit'])) {
// new form, we (re)set the session data
SmartyValidate::disconnect();
SmartyValidate::connect($smarty, true);
// register criteria
// Captcha
if ($config['showcap'] == 'y')
{
// if (!PhpLPCaptcha::Validate($_POST['captcha'])) {
// $captcha_error = '<p>Images Verification Failed</p>';
// $smarty->assign('captcha_error', $captcha_error);
// $fatal = true;
// }
SmartyValidate::register_object('PHPLPCaptcha', $PHPLPCaptcha);
SmartyValidate::register_criteria('ValidCaptcha','PHPLPCaptcha->Validate');
//SmartyValidate::register_validator('v_Captcha','PHPLP_Captcha','ValidCaptcha',false,false,'trim');
} |
its a bit of my long code that doesnt work
I tried both methods of validation, but no success , my template :
Code: |
{*validate id="v_Captcha" message="<p>Visual Verification Failed</p>"*}
{validate field="PHPLP_Captcha" criteria="ValidCaptcha" message="<p>Visual Verification Failed bro</p>"}
|
my form :
Code: | {if $config.showcap == 'y'}
<tr valign="baseline">
<th><label for="linkemail">*Visual Confirmation:</label>
<div class="desc">(Enter text as shown in the Picture. This is to prevent Automated Submissions and to confirm that Submission is being done by a Human.)</div></th>
<td><p style="padding: 2px; border: 1px solid #FCFCFC;"><img src="submit.php?action=captcha" width="200" height="60" alt="PHPLP Captcha" id="PHPLP Captcha" /> (Cant read? Click <a name="Captcha" href="Javascript: NewCaptcha();" >Refresh</a> to get a new one)</p>
<input type="text" name="PHPLP_Captcha" id="PHPLP_Captcha" style="width: 198px" maxlength="6" /><br />
(Letters are CaseInsensitive. There isnt any Zero.)
</td>
</tr>
{/if} |
It gives this error upon input :
Code: | Notice: SmartyValidate: [is_valid] method 'Validate' is not valid for object 'PHPLPCaptcha'. in D:\xampp\htdocs\linkexchangesystem\smarty\SmartyValidate.class.php on line 604 |
Can you please please please please please help me sir?? |
|
Back to top |
|
drizzt Smarty Rookie
Joined: 21 Jan 2008 Posts: 6
|
Posted: Wed Jan 27, 2010 11:18 am Post subject: problem with another form than "default" |
|
|
Hello everyone, and thanx monte for this great plugin.
However, I have a problem.
while testing my form (two fields, one validation), i repeatidly have this error:
Warning: Smarty error: validate: validator id 'femail' is not registered. in /home/dev/smarty/Smarty.class.php on line 1095
the form tpl :
Code: | <form method="post" action="" id="connexion" name="connexion" class="formConnexion">
<p><label class="text" for="email">Email :</label><input class="text" type="text" name="email" value="{$email|default:''|escape}" /><span class="warning">
{validate form="connexion" id="femail" message="Vous devez renseigner votre email" }</span></p>
<p><label class="text" for="mdp">Mot de passe :</label><input type="password" name="mdp" class="text" /><span class="note">6 car. min.</span></p>
<p class="envoy">
<label class="text"> </label><input type="submit" value="Connexion" /> <input type="reset" value="Effacer" />
</p>
</form> |
And the php :
Code: | if(empty($_POST)) {
// new form, we (re)set the session data
SmartyValidate::connect($smarty, true);
SmartyValidate::register_form('connexion');
SmartyValidate::register_validator('femail', 'email', 'isEmail', false, false, 'trim');
// display form
} else {
// validate after a POST
SmartyValidate::connect($smarty);
if(SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
} else {
// error, redraw the form
$smarty->assign($_POST);
}
} |
if i remove the form="connexion" from the tpl, in the validate tag, it works. So i don't know where is my mistake.
I was hoping to create 2 forms on the page (log in/new account) that's why this functionnality could help me.
If someone can help me, thanx in advance,
Julien |
|
Back to top |
|
drizzt Smarty Rookie
Joined: 21 Jan 2008 Posts: 6
|
Posted: Wed Jan 27, 2010 11:34 am Post subject: |
|
|
Finally, i found the mistake :
in the php, the register_validator need a parameter about the registered form.
Line concerned :
SmartyValidate::register_validator('femail', 'email', 'isEmail', false, false, 'trim','connexion');
Full code :
Code: |
if(empty($_POST)) {
// new form, we (re)set the session data
//echo 'premier affichage';
SmartyValidate::connect($smarty, true);
SmartyValidate::register_form('connexion');
SmartyValidate::register_validator('femail', 'email', 'isEmail', false, false, 'trim','connexion');
// display form
} else {
// validate after a POST
SmartyValidate::connect($smarty);
SmartyValidate::register_form('connexion');
if(SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
//echo 'good';
SmartyValidate::disconnect();
} else {
// error, redraw the form
//echo 'not good';
$smarty->assign($_POST);
}
}
|
|
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Wed Jul 21, 2010 8:30 pm Post subject: Fails with 3.0 rc1 - rc3 |
|
|
This plugin seems very nice! However for 3.0 compatibility it appears it needs some maintainance.
After it failed with 3.0 i tried it with 2.6.25 and it works perfectly.
I first tested the example with rc3 and i get a deprecated notices for each form field. When submitting anyway i get a fatal error. I've included the full errors below.
Any help would be appreciated I understand that solving this will not be trivial
--
i get multiple of these for the form displaying part
Notice: function call 'get_template_vars' is unknown or deprecated. in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 57
--
i get this when submitting
Notice: function call '_get_plugin_filepath' is unknown or deprecated. in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 57
Fatal error: Uncaught exception 'Exception' with message 'unknown method '_get_plugin_filepath'' in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php:117 Stack trace: #0 C:\xampp\xampp\htdocs\_smartytest2-3\libs\Smarty.class.php(763): Smarty_Internal_Wrapper->convert('_get_plugin_fil...', Array) #1 [internal function]: Smarty->__call('_get_plugin_fil...', Array) #2 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(490): Smarty->_get_plugin_filepath('validate_transf...', 'trim') #3 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(199): SmartyValidate::_execute_transform('trim', '', Array, Array, 'default') #4 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(285): SmartyValidate::_failed_fields(Array, 'default') #5 C:\xampp\xampp\htdocs\_smartytest2-3\validate\index.php(33): SmartyValidate::is_valid(Array) #6 {main} thrown in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 117 |
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Thu Jul 22, 2010 1:08 pm Post subject: |
|
|
I run SmartyValidate on 2.6.25 for now and think i found a minor bug:
SmartyValidate::is_registered_validator keeps returning false but defininately is running correctly.
I registered it for a non default form which is correctly registered (confirmed by SmartyValidate::is_registered_form).
The validator was registered earlier by SmartyValidate::register_validator.
Is there anything else i might have forgotten?
EDIT: SOLVED it, can't really tell what it was though, sorry.
Last edited by cycler on Thu Jul 22, 2010 2:53 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 22, 2010 1:45 pm Post subject: Re: Fails with 3.0 rc1 - rc3 |
|
|
cycler wrote: | This plugin seems very nice! However for 3.0 compatibility it appears it needs some maintainance.
After it failed with 3.0 i tried it with 2.6.25 and it works perfectly.
I first tested the example with rc3 and i get a deprecated notices for each form field. When submitting anyway i get a fatal error. I've included the full errors below.
Any help would be appreciated I understand that solving this will not be trivial
--
i get multiple of these for the form displaying part
Notice: function call 'get_template_vars' is unknown or deprecated. in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 57
--
i get this when submitting
Notice: function call '_get_plugin_filepath' is unknown or deprecated. in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 57
Fatal error: Uncaught exception 'Exception' with message 'unknown method '_get_plugin_filepath'' in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php:117 Stack trace: #0 C:\xampp\xampp\htdocs\_smartytest2-3\libs\Smarty.class.php(763): Smarty_Internal_Wrapper->convert('_get_plugin_fil...', Array) #1 [internal function]: Smarty->__call('_get_plugin_fil...', Array) #2 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(490): Smarty->_get_plugin_filepath('validate_transf...', 'trim') #3 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(199): SmartyValidate::_execute_transform('trim', '', Array, Array, 'default') #4 C:\xampp\xampp\htdocs\_smartytest2-3\libs\SmartyValidate.class.php(285): SmartyValidate::_failed_fields(Array, 'default') #5 C:\xampp\xampp\htdocs\_smartytest2-3\validate\index.php(33): SmartyValidate::is_valid(Array) #6 {main} thrown in C:\xampp\xampp\htdocs\_smartytest2-3\libs\sysplugins\smarty_internal_wrapper.php on line 117 |
It needs updated for 3.0. I'll do that after 3.0 is finalized. Basically get_template_vars needs to be getTemplateVars, and _get_plugin_filepath is being used to load plugins, it needs to use loadPlugin() instead. |
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Thu Jul 22, 2010 3:16 pm Post subject: |
|
|
newname wrote: | first of all.. Thanks for the great plugin.
It gives this error upon input :
Code: | Notice: SmartyValidate: [is_valid] method 'Validate' is not valid for object 'PHPLPCaptcha'. in D:\xampp\htdocs\linkexchangesystem\smarty\SmartyValidate.class.php on line 604 |
Can you please please please please please help me sir??
|
EDIT: Resolved! Don't get confused by this post. Instead check out a working example here : http://www.smarty.net/forums/viewtopic.php?p=65970#65946
I've also tried setting up a class method as a custom criteria over and over. I could, for the life of me not get it to work due to the same problem.
is_registered_criteria kept returning false *until* I did not set my form in the register_criteria call.
It then uses the default form and suddenly is_registered_criteria returns TRUE.
This is most likely a bug. I want to use my own form and class methods. Please help.
Last edited by cycler on Fri Jul 23, 2010 4:41 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 22, 2010 3:25 pm Post subject: |
|
|
From README:
Code: | function is_registered_criteria($func_name, $form = 'default') |
If you are not using the default form, you must supply the name as the 2nd param. This true with most every API function. |
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Thu Jul 22, 2010 7:37 pm Post subject: |
|
|
mohrt wrote: | From README:
Code: | function is_registered_criteria($func_name, $form = 'default') |
If you are not using the default form, you must supply the name as the 2nd param. This true with most every API function. |
EDIT: Resolved! Don't get confused by this post. Instead check out a working example here : http://www.smarty.net/forums/viewtopic.php?p=65970#65946
I'm aware of that I am saying if i supply my form name it doesn't work unless i omit it. My supplying the form parameter works for everything else though.
I specify my form param in every call and template (i.e. in register_form,register_validator,register_criteria,is_valid and in the {validate} tags). Everything works until i try adding my object and then the method as a custom criteria.
Perhaps you could write a working example with a custom validator method? And one more question: Is it allowed to register $this as an object?
Last edited by cycler on Fri Jul 23, 2010 4:43 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 22, 2010 7:43 pm Post subject: |
|
|
It should work something like:
Code: | SmartyValidate::register_object('myobj',$myobj);
SmartyValidate::register_criteria('isPass', 'myobj->test_password'); |
I'm not sure about registering $this, I don't think I've tried it. But it should work? It's just an instantiated object. Try it both ways. |
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Thu Jul 22, 2010 9:26 pm Post subject: |
|
|
EDIT: Resolved! Don't get confused by this post. Instead check out a working example here : http://www.smarty.net/forums/viewtopic.php?p=65970#65946
Ok i stopped working on my complex code and made the most basic implementation in order to get it right but no luck. Please look if there is anything out of the ordinary here on my end. Thanks for helping!
File : index.php
Code: |
<?php
require '../libs/Smarty.class.php';
require '../libs/SmartyValidate.class.php';
class Validator
{
public function test_password($value, $empty, &$params, &$formvars)
{
echo "test_password() was called, test succeeded!";
return true;
}
}
session_start();
$smarty =& new Smarty;
$myobj = new Validator();
if(empty($_POST))
{
SmartyValidate::connect($smarty, true);
SmartyValidate::register_object('myobj',$myobj);
SmartyValidate::register_criteria('isPass', 'myobj->test_password');
SmartyValidate::register_validator('validator_id_passwordfield', 'form_input_password', 'isPass', false, false, 'trim');
$smarty->display('form.tpl');
}
else
{
SmartyValidate::connect($smarty);
if(SmartyValidate::is_valid($_POST))
{
SmartyValidate::disconnect();
$smarty->display('success.tpl');
}
else
{
$smarty->assign($_POST);
$smarty->display('form.tpl');
}
}
?>
|
File : form.tpl
Code: |
<form method="post" action="index.php">
{validate id="validator_id_passwordfield" message="Validation says you messed up"}
Full Name: <input type="text" name="form_input_password"><br />
<input type="submit" name="submitOK" value="OK">
</form>
|
File: success.tpl
Code: |
Your form submission succeeded.
|
The error:
Code: |
Notice: SmartyValidate: [is_valid] method 'test_password' is not valid for object 'myobj'. in C:\xampp\xampp\htdocs\_smartytest2\libs\SmartyValidate.class.php on line 604
|
Last edited by cycler on Fri Jul 23, 2010 4:43 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 22, 2010 10:09 pm Post subject: |
|
|
The register_object() call does not survive between page submits, you have to register it on the POST as well. Your object is not serialized in the session for various reasons, you have to instantiate and assign.
Code: | <?php
require '../libs/Smarty.class.php';
require '../libs/SmartyValidate.class.php';
class Validator
{
public function test_password($value, $empty, &$params, &$formvars)
{
echo "test_password() was called, test succeeded!";
return true;
}
}
session_start();
$smarty =& new Smarty;
$myobj = new Validator();
if(empty($_POST))
{
SmartyValidate::connect($smarty, true);
SmartyValidate::register_object('myobj',$myobj);
SmartyValidate::register_criteria('isPass', 'myobj->test_password');
SmartyValidate::register_validator('validator_id_passwordfield', 'form_input_password', 'isPass', false, false, 'trim');
$smarty->display('form.tpl');
}
else
{
SmartyValidate::connect($smarty);
SmartyValidate::register_object('myobj',$myobj);
if(SmartyValidate::is_valid($_POST))
{
SmartyValidate::disconnect();
$smarty->display('success.tpl');
}
else
{
$smarty->assign($_POST);
$smarty->display('form.tpl');
}
}
?> |
|
|
Back to top |
|
cycler Smarty Rookie
Joined: 21 Jul 2010 Posts: 16
|
Posted: Fri Jul 23, 2010 4:37 pm Post subject: |
|
|
OK thanks! Glad I asked, i could never have figured that out by myself
Technically I could have expected this but on a logic level it is kind of confusing. Especially because the other assigns are not redone on POST.
Maybe it is a good idea to add this code example to the documentation? I know I would have liked to see it when I started out this week. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jul 23, 2010 7:16 pm Post subject: |
|
|
cycler wrote: | OK thanks! Glad I asked, i could never have figured that out by myself
Technically I could have expected this but on a logic level it is kind of confusing. Especially because the other assigns are not redone on POST.
Maybe it is a good idea to add this code example to the documentation? I know I would have liked to see it when I started out this week. |
Yeah, the documentation needs to address this specific case clearer. |
|
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
|
|