• Super User

    fare checkbox di copilazione obbligatoria con tpl- smarty tags

    su questa pagina web:
    http://www.lavorohotel.net/post/
    ho bisogno di rendere i 2 checkbox della privacy obbligatori, ma non so bene usare il codice tpl - smarty..


  • ModSenior

    Ciao matteoraggi,

    Per la realizzazione del plugin smarty potresti partire da questo codice e modificarlo secondo le tue esigenze. Sono costretto a fare copia e incolla qui perchè il repository SVN del progetto php5utils su sourceforge sta facendo i capricci.

    shared.amcheckbox.php
    [php]
    <?php
    /**

    • @package Tag Utils
    • @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
    • @version $Id: shared.amcheckbox.php 21 2007-02-26 01:06:26Z ftinti $
    • Required attributes
    • name
      
    • value
      
    • Optional attributes
    • multiline    boolean
      

    **/

    function smarty_amcheckbox($params, $smarty)
    {
    if ( !in_array('name', array_keys($params)) || empty($params['name']) )
    {
    $smarty->trigger_error("amcheckbox: missing 'name' parameter");
    }
    $name = $params['name'];

    $bare = "";
    if ( in_array('bare', array_keys($params)) && !empty($params['bare']) )
    {
        $bare = $params['bare'];
    }
    
    $multiline = "";
    if ( in_array('multiline', array_keys($params)) && !empty($params['multiline']) )
    {
        $multiline = $params['multiline'];
    }
    
    $result = "";
    if ($bare)
    {
        if ($value)
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" checked="checked" />';
        }
        else
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" />';
        }
        $result .= '<input type="hidden" name="_' . $name . '" />';
    }
    else if ($multiline)
    {
        $result .= '<div class="formelement">'
                 . '<label for="' . $name . '">' . $name . '</label>';
        if ($value)
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" checked="checked" />';
        }
        else
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" />';
        }
        $result .= '<input type="hidden" name="_' . $name . '" />'
                 . '<div class="clear"><!--  --></div></div>';
    }
    else
    {
        $result  .= '<span class="formelement">';
        if ($value)
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" checked="checked" />';
        }
        else
        {
            $result .= '<input type="checkbox" name="' . $name . '" id="' . $name . '" value="true" class="checkbox" />';
        }
        $result .= '<input type="hidden" name="_' . $name . '" />';
        $result .= '<span class="chlabel">' . $path . '</span>';
        $result .= '</span>';
    }
    
    return $result;
    

    }
    ?>
    [/php]function.checkbox.php
    [php]
    <?php
    /**

    • @package Tag Utils
    • @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
    • @version $Id: function.checkbox.php 21 2007-02-26 01:06:26Z ftinti $
    • Required attributes
    • name
      
    • value
      
    • Optional attributes
    • type        string
      
    • cssclass    string
      
    • style        string
      
    • maxlength    integer
      
    • readonly    boolean
      
    • disabled    string
      

    **/
    function smarty_function_checkbox($params, $smarty)
    {
    require_once $smarty->_get_plugin_filepath('shared','amcheckbox');
    $result = smarty_amcheckbox($params, $smarty);
    return $result;
    }
    ?>
    [/php]