View previous topic :: View next topic |
Author |
Message |
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Fri Oct 22, 2004 7:54 pm Post subject: |
|
|
what about doing this in the Template?
Code: |
{ validate }
<form> {* no name, except there are several forms!*}
<message value="There were errors on your form!" />
<field name="username">
<tag name="username_is_empty">
<criteria name="isNotEmpty" />
<transform name="trim" />
<message value="Username cannot be empty!" />
</tag>
</field>
<field name="password">
<tag name="password_is_empty">
<criteria name="isNotEmpty" />
<transform name="trim" />
<message value="Password cannot be empty!" />
</tag>
<tag name="password_not_match">
<criteria name="isEqual" field2="password2" />
<message value="Passwords do not match!" />
</tag>
</field>
</form>
{ validate }
<input type='text' name='username'/>
<input type='text' name='password'/>
|
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Oct 22, 2004 8:00 pm Post subject: |
|
|
What are you gaining, besides a lot of complexity? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Oct 23, 2004 12:36 am Post subject: |
|
|
Abstraction? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Oct 23, 2004 3:36 am Post subject: |
|
|
in the template? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Oct 23, 2004 4:00 am Post subject: |
|
|
It looks similar to the idea of XForms where the look-and-feel is distinguished from the actions to be taken. In XForms, the action description is in the head of the document while the display description is in the body. I see the idea being that the declaration of properties and relationships is a different thing than the declaration of the presentation itself. I'm not sure how keen I am on XForms, but there is precedence for this type of separation.
I don't suppose that SmartyValidate is after the same target that XForms aims for, so the extra abstraction may not be warranted. Still, I think it makes a fair discussion point. |
|
Back to top |
|
DonJ Smarty n00b
Joined: 12 Nov 2004 Posts: 1
|
Posted: Fri Nov 12, 2004 1:11 am Post subject: |
|
|
I have a couple of problems getting this to work.
My template looks like this:
[php:1:c1eca8a458]
<form action="{$form_url}" method="post">
<p>
{foreach from=$errormsgs item=errormsg}{strip}
{$errormsg}<br>
{/strip}{/foreach}
{validate field="newpw" criteria="isEqual" field2="newpw2" message="Passwords do not match" append="errormsgs" halt="yes"}
{validate field="newpw2" criteria="isRange" low="3" high="5" message="Password must be in range" append="errormsgs"}
{validate field="newpw2" criteria="isRegExp" expression="/^([a-zA-Z0-9])*$/" message="Password must not contain any special chars and whitespaces"}
</p><p>
New Password: <INPUT TYPE="PASSWORD" name="newpw"><br>
Repeat new password: <INPUT TYPE="PASSWORD" name="newpw2"><br>
<INPUT TYPE="SUBMIT" value="Change password">
</from>
[/php:1:c1eca8a458]
And the form points to this php code:
[php:1:c1eca8a458]<?php
session_start();
ob_start();
header("Cache-control: private");
...
class ..
//form validation
if(!SmartyValidate::is_valid($_POST)) {
$this->view($acct);
return false;
}
SmartyValidate::disconnect();
$this->save();
..
?>[/php:1:c1eca8a458]
I get all the time the erorr: Password must be in range (although it is in range) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Nov 12, 2004 3:54 pm Post subject: |
|
|
use isLength instead of isRange. |
|
Back to top |
|
AcidMaX Smarty Rookie
Joined: 26 Nov 2003 Posts: 16
|
Posted: Wed Nov 17, 2004 10:04 pm Post subject: |
|
|
It appears SmartyValidate does not want to validate when the field name is something like
test[test_field]
{validate field="test[test_field]" criteria="notEmpty" message="* REQUIRED *"}
<input type="text" name="test[test_field]" value="{$test.test_field}">
My code and everything works fine if I just make the field something like test_field, but with test[test_field] it doesnt seem to work. Maybe its not recognizing the field name as an array, like POST does? I tried field =test.test_field as well in the validate tag. Any ideas?
Thanks,
Andy |
|
Back to top |
|
AcidMaX Smarty Rookie
Joined: 26 Nov 2003 Posts: 16
|
|
Back to top |
|
Timm Smarty n00b
Joined: 21 Nov 2004 Posts: 2
|
Posted: Sun Nov 21, 2004 3:28 pm Post subject: |
|
|
I think I've discovered a bug.
You've something like that in your code (SmartyValidate.class.php, line 152):
Code: |
if($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form))
$formvars[$_field] = $_new_val;
|
The problem here is the if-statement.
I had a textfield which should get trimmed. For example, somebody entered " " (without the quotes). Then this string gets trimmed, and the result is an empty string (length: 0)
Then this looks something like that:
But the if-statement will evaluate to false, meaning the following block will not be executed. This will cause the string to stay untrimmed.
By the way: What's the if-statement for?
Hope it helps. |
|
Back to top |
|
Daisuke Sano Smarty n00b
Joined: 20 Dec 2004 Posts: 2
|
Posted: Mon Dec 20, 2004 6:36 am Post subject: |
|
|
I've met the same problem about the 'trim' transformer.
I hope you resolve this problem any way.
For example, the following patch is useful?
Any problem?
Code: | *** libs/SmartyValidate.class.php 2004-07-13 23:48:08.000000000 +0900
--- /home/ymmt/ogre_code/code/smarty/libs/SmartyValidate.class.php 2004-12-20 14:13:20.000000000 +0900
***************
*** 149,156 ****
$formvars[$_field][$_x] = $_new_val;
}
} else {
! if($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form))
! $formvars[$_field] = $_new_val;
}
}
}
--- 149,157 ----
$formvars[$_field][$_x] = $_new_val;
}
} else {
! $_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form);
! if($_new_val !== false)
! $formvars[$_field] = $_new_val;
}
}
}
|
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Dec 20, 2004 2:52 pm Post subject: |
|
|
That is a bug, it was being tested correctly in the if statement above it, but not the else. The fix is committed to CVS. |
|
Back to top |
|
Daisuke Sano Smarty n00b
Joined: 20 Dec 2004 Posts: 2
|
Posted: Wed Dec 22, 2004 12:16 am Post subject: |
|
|
Thank you so much! |
|
Back to top |
|
jflaflamme Smarty n00b
Joined: 29 Jun 2005 Posts: 1
|
Posted: Wed Jun 29, 2005 6:08 pm Post subject: |
|
|
Hi,
I've read doc, searched forums, tried multiple combinations file[] or file etc ..
I try to validate a file array.
I have field like this <input name="fichiers[]" type="file" id="fichiers[]" ...
my validation is :
{validate page = "1" id = "v_fichiers" message = "whatever"}
in PHP
SmartyValidate::register_validator('v_fichiers', 'fichiers:10k','isFileSize', false, false);
The only explaination i see is, SmartyValidate doesn't support $_FILES arrays ...
Am i right ?
Thanks in advance and keep up your good work ! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 29, 2005 8:08 pm Post subject: |
|
|
You would have to choose a particular element such as fichiers[0], or write a custom validator that traverses your array. |
|
Back to top |
|
|