Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

A plugin for redisplaying form input

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Tue Jul 01, 2003 9:31 pm    Post subject: A plugin for redisplaying form input Reply with quote

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
View user's profile Send private message
LuCarD
Smarty n00b


Joined: 02 Jul 2003
Posts: 1

PostPosted: Wed Jul 02, 2003 3:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Wed Jul 02, 2003 7:33 pm    Post subject: Reply with quote

LuCarD,

The problem I have with your solution is that is too much templated Laughing

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
View user's profile Send private message
Nico
Smarty n00b


Joined: 09 Oct 2003
Posts: 1
Location: Location

PostPosted: Thu Oct 09, 2003 9:55 am    Post subject: Reply with quote

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 Question

Nicolas
Back to top
View user's profile Send private message Send e-mail
Justin
Smarty Regular


Joined: 07 May 2003
Posts: 38
Location: Vilnius, Lithuania

PostPosted: Thu Oct 09, 2003 6:19 pm    Post subject: Reply with quote

I think formsess is much better. more info - http://www.phpinsider.com/smarty-forum/viewtopic.php?t=30
_________________
http://www.baubas.net
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP