 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
surfingtom Smarty Rookie
Joined: 19 Apr 2005 Posts: 10
|
Posted: Tue Apr 19, 2005 7:46 pm Post subject: Smarty Validate 2.4 - append problem |
|
|
I am using version 2. and am unable to get the append messages to print out. The messages print fine if they are not appended. I have tried to get it to work with the sample script supplied with the plug in and still no luck. Maybe its just getting to late in the day but this is starting to do my head in !
Here is form.tpl:
| Code: |
<html>
<head>
<title>Smarty</title>
</head>
<body>
{section name=error loop=$errors}
error: {$errors[error]}<br>
{/section}
<form method="post" action="test-validation.php?test=hello">
{validate id="fullname" message="Full Name Cannot Be Empty" append=errors}
Full Name: <input type="text" name="FullName" value="{$FullName|escape}"><br />
{validate id="phone" message="Phone Number Must be a Number" append=errors}
Phone :<input type="text" name="Phone" value="{$Phone|escape}" empty="yes"><br />
{validate id="expdate" message="Exp Date not valid" append=errors}
Exp Date: <input type="text" name="CCExpDate" size="8" value="{$CCExpDate|escape}"><br />
{validate id="email" message="Email not valid" append=errors}
Email: <input type="text" name="Email" size="30" value="{$Email|escape}"><br />
{validate id="date" message="Date not valid" append=errors}
Date: <input type="text" name="Date" size="10" value="{$Date|escape}"><br />
{validate id="password" message="passwords do not match" append=errors}
password: <input type="password" name="password" size="10" value="{$password|escape}"><br />
password2: <input type="password" name="password2" size="10" value="{$password2|escape}"><br />
<input type="submit">
</form> </body>
</html> |
here is test-validation:-
| Code: |
<?php
session_start();
// you will need to setup Smarty if
// the defaults are not correct.
require('./festival_smarty.php');
require('/usr/local/lib/php/Smarty/SmartyValidate.class.php');
$smarty =& new FestivalSmarty;
if(empty($_POST)) {
// new form, we (re)set the session data
SmartyValidate::connect($smarty, true);
// register our validators
SmartyValidate::register_validator('fullname', 'FullName', 'notEmpty',
false, false, 'trim');
SmartyValidate::register_validator('phone', 'Phone', 'isNumber', true,
false, 'trim');
SmartyValidate::register_validator('expdate', 'CCExpDate', 'notEmpty',
false, false, 'trim');
SmartyValidate::register_validator('email', 'Email', 'isEmail', false,
false, 'trim');
SmartyValidate::register_validator('date', 'Date', 'isDate', true,
false, 'trim');
SmartyValidate::register_validator('password', 'password:password2', 'isEqual');
// display form
$smarty->display('form.tpl');
} else {
// validate after a POST
SmartyValidate::connect($smarty);
if(SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
$smarty->display('success.tpl');
} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->display('form.tpl');
}
}
?> |
and success.tpl is just some text saying success.
Can anyone see what is wrong? Basically it prionts out as you would expect without the appended messages. I.e. if you enter two invalid fields, you get two lines with 'error:' printed, but no error message.
Many thanks to anyone who can help.
Tom B.
p.s. big thankyou to the plugin designer for a very useful plugin (once I get it to work;-) ) |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7042 Location: Lincoln Nebraska, USA
|
Posted: Tue Apr 19, 2005 8:00 pm Post subject: |
|
|
They get assigned as an associative array:
| Code: | {foreach loop=$errors key="key" item="val"}
{$key} {$val}
{/foreach} |
|
|
| Back to top |
|
surfingtom Smarty Rookie
Joined: 19 Apr 2005 Posts: 10
|
Posted: Tue Apr 19, 2005 9:26 pm Post subject: Fantastic - thankyou! |
|
|
Hi,
Aaahh! Stupid me - thankyou. Incidently for anyone else who reads this who may have a problem, it should be
| Code: |
{foreach from=$errors key="key" item="val"}
{key}{val}
{/foreach}
|
not loop.
Many thanks indeed - maybe you could add this into your example that you include in your plugin as I have noticed a couple of other people were having problems with getting hold of the append messages. Fantastic plugin - thankyou  |
|
| Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5613 Location: Toronto, Canada
|
Posted: Tue Apr 19, 2005 10:41 pm Post subject: |
|
|
Sorry, I can't help myself --- this is the correction of the correction
| Code: | {foreach from=$errors key="key" item="val"}
{$key}{$val}
{/foreach} |
|
|
| 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
|