|
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 |
fbronx Smarty Rookie
Joined: 28 May 2003 Posts: 11 Location: Stekene, Belgium
|
Posted: Tue Jul 01, 2003 9:31 pm Post subject: A plugin for redisplaying form input |
|
|
I use the following plugin to redisplay forms (when an error occurs for instance) with the input of the user.
Code: | function smarty_form_value($params, &$smarty)
{
extract($params);
if ( ! isset($var) )
{
$smarty->trigger_error("form_value: missing 'var' parameter");
return;
}
if ( isset($_POST[$var]) )
return $_POST[$var];
else
return $smarty->get_template_vars($var);
} |
in a template :
Code: | <input type="text" id="user_name" name="user_name" value="{form_value var=user_name}" size="30" /> |
|
|
Back to top |
|
LuCarD Smarty n00b
Joined: 02 Jul 2003 Posts: 1
|
Posted: Wed Jul 02, 2003 3:01 pm Post subject: |
|
|
Code: | function smarty_function_textbox($params, &$smarty)
{
foreach($params as $key=>$value){
unset($params[$key]);
$params[strtolower($key)] = $value;
}
if (empty($params['name'])) {
$smarty->_trigger_fatal_error("[textbox plugin] parameter 'name' cannot be empty");
return;
}
if (empty($params['class'])) {
$params['class'] = "defaultInput";
}
if (!isset($params['value'])) {
$params['value']="";
}
else {
if (strpos($params['value'],"sql:select") === false) {
$params['value']=htmlspecialchars($params['value']);
}
else {
if (!isset($GLOBALS['mysql']) || !is_object($GLOBALS['mysql'])) {
new dbconnect;
}
$GLOBALS['mysql']->do_query( str_replace( "limit 1" , "" , substr( $params['value'], 4 ) ). " limit 1" );
$options=$GLOBALS['mysql']->fetch_array(true);
$params['value']=$options[0];
}
}
if (isset($params['display']) && $params['display']==1) {
$content =$params['value'];
}
else {
$content = "<INPUT type='textbox' ";
foreach($params as $key=>$value){
if ($key=="assign") continue;
$content .= $key . "='" . $value ."' ";
}
$content .= " />";
}
if (!empty($params['assign'])) {
$smarty->assign($params['assign'],$content);
} else {
return $content;
}
} |
and in the template I use
Code: |
<% textbox name="first_name" value=$data.first_name %>
|
$data is validated posted data in my script
And for all form items I got similar script... Makes it very easy for me create form pages. |
|
Back to top |
|
fbronx Smarty Rookie
Joined: 28 May 2003 Posts: 11 Location: Stekene, Belgium
|
Posted: Wed Jul 02, 2003 7:33 pm Post subject: |
|
|
LuCarD,
The problem I have with your solution is that is too much templated
I like to work with an HTML editor and look in a browser how it will look before I integrate it.
Franky. |
|
Back to top |
|
Nico Smarty n00b
Joined: 09 Oct 2003 Posts: 1 Location: Location
|
Posted: Thu Oct 09, 2003 9:55 am Post subject: |
|
|
Fbronx,
The script you posted is interesting but I was wondering how to solve the following problem :
how to redisplay a list of quoted/unquoted checkboxes with names like region[] and different values for each boxes ?
Any Idea
Nicolas |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
|
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
|