xoops forums

McNaz

Just can't stay away
Posted on: 2004/11/4 14:05
McNaz
McNaz (Show more)
Just can't stay away
Posts: 574
Since: 2003/4/21
#1

Form Validation

Hi everyone.

I'm getting to the stage where my only issue with PHP and XOOPS is form validation. It is such a pain to do form validation in code so I've started looking into a possible solution.

One that did catch my attention is SmartyValidate. This works by adding validation in the html itself as Smarty markup.

More information can be found here. So an example html page would be :

<form method="POST" action="index.php">
    
    {
validate field="FullName" criteria="notEmpty" message="Full Name cannot be empty"}
    
Full Name: <input type="text" name="FullName">
    
    {
validate field="Date" criteria="isDate" message="Date is not valid"}
    
Date: <input type="text" name="Date">
    
    <
input type="submit">
    </
form>


The validation works by :

session_start();
    require(
'Smarty.class.php');
    require(
'SmartyValidate.class.php');
    
    
$smarty =& new Smarty;
    
    
// required initialization
    
SmartyValidate::connect($smarty);
    
    if(empty(
$_POST)) {
       
$smarty->display('form.tpl');
    } else {    
       
// validate after a POST
       
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');
       }
    }


I know that $XoopsTpl is extended from the Smarty class so the above example code can be tweaked to work (in theory anyway). I've had a very brief play with this (30 mins) without any luck.

Another interesting website with a solution can be found here.

Personally I prefer the SartValidate solution but that would involve uploading the smarty plugin files and SmartyValidate into class/smarty. Although not difficult itself it can becomre tedious when updating several sites etc.

So the quaestion is: has anyone implemented a good validation scheme that is reusable? Is one planned for Xoops? Would anyone be interested if I attempted to integrate either of the above two solutions into Xoops? I know XoopsForms has simple required tags that can be added but that is as far as it goes :(

Thoughts, suggestions and ideas are most welcome.

Cheers.

McNaz.

McNaz

Just can't stay away
Posted on: 2004/11/5 16:21
McNaz
McNaz (Show more)
Just can't stay away
Posts: 574
Since: 2003/4/21
#2

Re: Form Validation

Hi all again.

I've had some luck in integrating SmartyValidation into Xoops. What follows is a modified template.php file from the XOOPS class directory:

You can get SmartyValidation from here.

<?php
// $Id: template.php,v 1.20 2003/07/08 12:38:08 okazu Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <https://xoops.org/>  &nbs ... nbsp;   //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/https://xoops.org/http://www.xoopscube.jp/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //

if (!defined('SMARTY_DIR')) {
    exit();
}
/**
 * Base class: Smarty template engine
 */
require_once SMARTY_DIR.'Smarty.class.php';
require_once 
SMARTY_DIR.'SmartyValidate.class.php';

/**
 * Template engine
 *
 * @package        kernel
 * @subpackage    core
 *
 * @author        Kazumi Ono     <onokazu@xoops.org>
 * @copyright    (c) 2000-2003 The XOOPS Project - www.xoops.org
 */
class XoopsTpl extends Smarty
{

    
/**
     * Allow update of template files from the themes/ directory?
     * This should be set to false on an active site to increase performance
     */
    
var $_canUpdateFromFile false;

    
/**
     * Constructor
     **/
    
function XoopsTpl()
    {
        global 
$xoopsConfig;
        
$this->Smarty();
        
$this->compile_id null;
        if (
$xoopsConfig['theme_fromfile'] == 1) {
            
$this->_canUpdateFromFile true;
            
$this->compile_check true;
        } else {
            
$this->_canUpdateFromFile false;
            
$this->compile_check false;
        }
        
$this->left_delimiter =  '<{';
        
$this->right_delimiter =  '}>';
        
$this->template_dir XOOPS_THEME_PATH;
        
$this->cache_dir XOOPS_CACHE_PATH;
        
$this->compile_dir XOOPS_COMPILE_PATH;
        
$this->plugins_dir = array(XOOPS_ROOT_PATH.'/class/smarty/plugins');
        
$this->default_template_handler_func 'xoops_template_create';
        
        
// Added by goghs on 11-26 to deal with safe mode
        //if (ini_get('safe_mode') == "1") {
            
$this->use_sub_dirs false;
        
//} else {
        //    $this->use_sub_dirs = true;
        //}
        // END

        
$this->assign(array('xoops_url' => XOOPS_URL'xoops_rootpath' => XOOPS_ROOT_PATH'xoops_langcode' => _LANGCODE'xoops_charset' => _CHARSET'xoops_version' => XOOPS_VERSION'xoops_upload_url' => XOOPS_UPLOAD_URL));
    }

    
/**
     * Set the directory for templates
     * 
     * @param   string  $dirname    Directory path without a trailing slash
     **/
    
function xoops_setTemplateDir($dirname)
    {
        
$this->template_dir $dirname;
    }

    
/**
     * Get the active template directory
     * 
     * @return  string
     **/
    
function xoops_getTemplateDir()
    {
        return 
$this->template_dir;
    }

    
/**
     * Set debugging mode
     * 
     * @param   boolean     $flag
     **/
    
function xoops_setDebugging($flag=false)
    {
        
$this->debugging is_bool($flag) ? $flag false;
    }

    
/**
     * Set caching
     * 
     * @param   integer     $num
     **/
    
function xoops_setCaching($num=0)
    {
        
$this->caching = (int)$num;
    }

    
/**
     * Set cache lifetime
     * 
     * @param   integer     $num    Cache lifetime
     **/
    
function xoops_setCacheTime($num=0)
    {
        
$num = (int)$num;
        if (
$num <= 0) {
            
$this->caching 0;
        } else {
            
$this->cache_lifetime $num;
        }
    }

    
/**
     * Set directory for compiled template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCompileDir($dirname)
    {
        
$this->compile_dir $dirname;
    }

    
/**
     * Set the directory for cached template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCacheDir($dirname)
    {
        
$this->cache_dir $dirname;
    }

    
/**
     * Render output from template data
     * 
     * @param   string  $data
     * @return  string  Rendered output  
     **/
    
function xoops_fetchFromData(&$data)
    {
        
$dummyfile XOOPS_CACHE_PATH.'/dummy_'.time();
        
$fp fopen($dummyfile'w');
        
fwrite($fp$data);
        
fclose($fp);
        
$fetched $this->fetch('file:'.$dummyfile);
        
unlink($dummyfile);
        
$this->clear_compiled_tpl('file:'.$dummyfile);
        return 
$fetched;
    }

    
/**
     * 
     **/
    
function xoops_canUpdateFromFile()
    {
        return 
$this->_canUpdateFromFile;
    }
  
//
  
function validConnect()
  {
    
SmartyValidate::connect($this);   
  }
  
//
  
function validDisconnect()
  {
    
SmartyValidate::disconnect($this);
  }
  
//
  
function validate($post)
  {
    return 
SmartyValidate::is_valid($post);
  }
  
//
  
function redisplay($post)
  {
    
$this->assign($post);
    
//$this->display
  
}

}

/**
 * Smarty default template handler function
 * 
 * @param $resource_type
 * @param $resource_name
 * @param $template_source
 * @param $template_timestamp
 * @param $smarty_obj
 * @return  bool
 **/
function xoops_template_create ($resource_type$resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
{
    if ( 
$resource_type == 'db' ) {
        
$file_handler =& xoops_gethandler('tplfile');
        
$tpl =& $file_handler->find('default'nullnullnull$resource_nametrue);
        if (
count($tpl) > && is_object($tpl[0])) {
            
$template_source $tpl[0]->getSource();
            
$template_timestamp $tpl[0]->getLastModified();
            return 
true;
        }
    } else {
    }
    return 
false;
}

/**
 * function to update compiled template file in templates_c folder
 * 
 * @param   string  $tpl_id
 * @param   boolean $clear_old
 * @return  boolean
 **/
function xoops_template_touch($tpl_id$clear_old true)
{
    
$tpl = new XoopsTpl();
    
$tpl->force_compile true;
    
$tplfile_handler =& xoops_gethandler('tplfile');
    
$tplfile =& $tplfile_handler->get($tpl_id);
    if ( 
is_object($tplfile) ) {
        
$file $tplfile->getVar('tpl_file');
        if (
$clear_old) {
            
$tpl->clear_cache('db:'.$file);
            
$tpl->clear_compiled_tpl('db:'.$file);
        }
        
$tpl->fetch('db:'.$file);
        return 
true;
    }
    return 
false;
}

/**
 * Clear the module cache
 * 
 * @param   int $mid    Module ID
 * @return 
 **/
function xoops_template_clear_module_cache($mid)
{
    
$block_arr =& XoopsBlock::getByModule($mid);
    
$count count($block_arr);
    if (
$count 0) {
        
$xoopsTpl = new XoopsTpl();    
        
$xoopsTpl->xoops_setCaching(2);
        for (
$i 0$i $count$i++) {
            if (
$block_arr[$i]->getVar('template') != '') {
                
$xoopsTpl->clear_cache('db:'.$block_arr[$i]->getVar('template'));
            }
        }
    }
}
?>



Usage code would be:

case 'showform':
  
//header include code
  
$xoopsOption['template_main'] = 'module_data_entry.html';
  
$xoopsTpl->calidConnect();
  
$xoopsTpl->assign('value',$somevalue);
  
//footer include code
  
break;

case 
'savedata'//comes in from a post from module_data_entry.html
  //header include code
  
$xoopsTpl->ValidConnect();
  if (
$xoopsTpl->validate($_POST)){
    
$xoopsTpl->validDisconnect();
    
redirect_header('index.php',3,'data saved';}
  else {
    
$xoopsTpl->assign($_POST); 
    
//footer include code}}
  
break;


Read the included README file in SmartyValidate for an example of the Smarty validation markup to have in the template file. Best of all, the validation is compiled into the template cache!!!

The XOOPS integration is still rough and is working great at the moment.

Cheers.

McNaz

DogTags

Just popping in
Posted on: 2005/5/7 13:50
DogTags
DogTags (Show more)
Just popping in
Posts: 50
Since: 2004/12/4
#3

Re: Form Validation

Can this be done on a form-by-form basis? I mean, can you call certain validation for form X and other validation for form Y ?

Thanks

cosmodrum

Just popping in
Posted on: 2006/5/28 21:46
cosmodrum
cosmodrum (Show more)
Just popping in
Posts: 24
Since: 2004/8/30
#4

Re: Form Validation

Hi

Im trying to integrate the smartyValidate into XOOPS 2.2.4, i got no errors but no validation progress also. Please look into my code and maybe you can help.

Im trying to port a directory script [phpLD]with smarty to xoops. The frontend is almost converted, but validation does not work
Here are the files:

templates.php

<?php
// $Id: template.php,v 1.21.6.16 2005/07/22 18:22:58 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <https://xoops.org/>  &nbs ... nbsp;   //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/https://xoops.org/http://www.xoopscube.jp/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //

if (!defined('SMARTY_DIR')) {
    exit();
}
/**
 * Base class: Smarty template engine
 */
require_once SMARTY_DIR.'Smarty.class.php';
require_once 
SMARTY_DIR.'SmartyValidate.class.php';

/**
 * Template engine
 *
 * @package        kernel
 * @subpackage    core
 *
 * @author        Kazumi Ono     <onokazu@xoops.org>
 * @copyright    (c) 2000-2003 The XOOPS Project - www.xoops.org
 */
class XoopsTpl extends Smarty
{

    
/**
     * Allow update of template files from the themes/ directory?
     * This should be set to false on an active site to increase performance
     */
    
var $_canUpdateFromFile false;

    
/**
     * Constructor
     **/
    
function XoopsTpl()
    {
        global 
$xoopsConfig;
        
$this->Smarty();
        
$this->compile_id null;
        if (
$xoopsConfig['theme_fromfile'] == 1) {
            
$this->_canUpdateFromFile true;
            
$this->compile_check true;
        } else {
            
$this->_canUpdateFromFile false;
            
$this->compile_check false;
        }
        
$this->left_delimiter =  '<{';
        
$this->right_delimiter =  '}>';
        
$this->template_dir XOOPS_THEME_PATH;
        
$this->cache_dir XOOPS_CACHE_PATH;
        
$this->compile_dir XOOPS_COMPILE_PATH;
        
$this->plugins_dir = array(XOOPS_ROOT_PATH.'/class/smarty/plugins');
        
$this->default_template_handler_func 'xoops_template_create';

        
// Added by goghs on 11-26 to deal with safe mode
        //if (ini_get('safe_mode') == "1") {
        
$this->use_sub_dirs false;
        
//} else {
        //    $this->use_sub_dirs = true;
        //}
        // END
    
}

    
/**
     * Set the directory for templates
     * 
     * @param   string  $dirname    Directory path without a trailing slash
     **/
    
function xoops_setTemplateDir($dirname)
    {
        
$this->template_dir $dirname;
    }

    
/**
     * Get the active template directory
     * 
     * @return  string
     **/
    
function xoops_getTemplateDir()
    {
        return 
$this->template_dir;
    }

    
/**
     * Set debugging mode
     * 
     * @param   boolean     $flag
     **/
    
function xoops_setDebugging($flag=false)
    {
        
$this->debugging is_bool($flag) ? $flag false;
    }

    
/**
     * Set caching
     * 
     * @param   integer     $num
     **/
    
function xoops_setCaching($num=0)
    {
        
$this->caching = (int)$num;
    }

    
/**
     * Set cache lifetime
     * 
     * @param   integer     $num    Cache lifetime
     **/
    
function xoops_setCacheTime($num=0)
    {
        
$num = (int)$num;
        if (
$num <= 0) {
            
$this->caching 0;
        } else {
            
$this->cache_lifetime $num;
        }
    }

    
/**
     * Set directory for compiled template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCompileDir($dirname)
    {
        
$this->compile_dir $dirname;
    }

    
/**
     * Set the directory for cached template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCacheDir($dirname)
    {
        
$this->cache_dir $dirname;
    }

    
/**
     * Render output from template data
     * 
     * @param   string  $data
     * @return  string  Rendered output  
     **/
    
function xoops_fetchFromData(&$data)
    {
        
$dummyfile XOOPS_CACHE_PATH.'/dummy_'.time();
        
$fp fopen($dummyfile'w');
        
fwrite($fp$data);
        
fclose($fp);
        
$fetched $this->fetch('file:'.$dummyfile);
        
unlink($dummyfile);
        
$this->clear_compiled_tpl('file:'.$dummyfile);
        return 
$fetched;
    }

    
/**
     * 
     **/
    
function xoops_canUpdateFromFile()
    {
        return 
$this->_canUpdateFromFile;
    }
    
    
/**
     * Get caching
     * 
     * @return int
     **/
    
function xoops_getCaching()
    {
        return 
$this->caching;
    }
    
    
    
/////////////////////////
    
      //
  
function validConnect()
  {
    
SmartyValidate::connect($this);   
  }
  
//
  
function validDisconnect()
  {
    
SmartyValidate::disconnect($this);
  }
  
//
  
function validate($post)
  {
    return 
SmartyValidate::is_valid($post);
  }
  
//
    
function redisplay($post)
  {
    
$this->assign($post);
    
//$this->display
  
}


    
/////////////////////////////////
    
    
    
    
}

/**
 * Smarty default template handler function
 * 
 * @param $resource_type
 * @param $resource_name
 * @param $template_source
 * @param $template_timestamp
 * @param $smarty_obj
 * @return  bool
 **/
function xoops_template_create ($resource_type$resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
{
    if ( 
$resource_type == 'db' ) {
        
$file_handler =& xoops_gethandler('tplfile');
        
$tpl =& $file_handler->find('default'nullnullnull$resource_nametrue);
        if (
count($tpl) > && is_object($tpl[0])) {
            
$template_source $tpl[0]->getSource();
            
$template_timestamp $tpl[0]->getLastModified();
            return 
true;
        }
    } else {
    }
    return 
false;
}

/**
 * function to update compiled template file in templates_c folder
 * 
 * @param   string  $tpl_id
 * @param   boolean $clear_old
 * @return  boolean
 **/
function xoops_template_touch($tplfile$clear_old true)
{
    
$tpl = new XoopsTpl();
    
$tpl->force_compile true;
    if ( 
is_object($tplfile) ) {
        
$file $tplfile->getVar('tpl_file');
        if (
$clear_old) {
            
$tpl->clear_cache('db:'.$file);
            
$tpl->clear_compiled_tpl('db:'.$file);
        }
        
$tpl->fetch('db:'.$file);
        return 
true;
    }
    return 
false;
}

/**
 * Clear the module cache
 * 
 * @param   int $mid    Module ID
 * @return 
 **/
function xoops_template_clear_module_cache($mid)
{
    
$block_handler =& xoops_gethandler('block');
    
//note this uses backwards parameters for backwards compatibility - change that!
    
$block_arr =& $block_handler->getByModule($midtruefalse);
    if (
count($block_arr) > 0) {
        
$instance_handler =& xoops_gethandler('blockinstance');
        
$instances =& $instance_handler->getObjects(new Criteria('bid'"(".implode(','array_keys($block_arr)).")""IN"));
        
$count count($instances);
        if (
$count 0) {
            
$xoopsTpl = new XoopsTpl();
            
$xoopsTpl->xoops_setCaching(2);
            for (
$i 0$i $count$i++) {
                if (
$block_arr[$instances[$i]->getVar('bid')]->getVar('template') != '') {
                    
$xoopsTpl->clear_cache('db:'.$block_arr[$instances[$i]->getVar('bid')]->getVar('template'), 'blk_'.$instances[$i]->getVar('instanceid'));
                }
            }
        }
    }
}
?>



submit.php

<?php
/**
 * Project:     PHPLinkDirectory: Link exchange directory
 *
 * License: GNU GPL (http://www.opensource.org/licenses/gpl-license.html)
 * 
 * This program is free software;
 * 
 * you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * For questions, help, comments, discussion, etc., please join the
 * PHP Link Directory Forum http://www.phplinkdirectory.com/forum/

 *
 * @link http://www.phplinkdirectory.com/
 * @copyright 2004-2005 NetCreated, Inc. (http://www.netcreated.com/)
 * @projectManager David DuVal <david@david-duval.com>
 * @author Bogdan Dumitru <dcb@insomniacsoft.com>
 * @mod developers and support
 *         Casey Wilson / Ap0s7le <at@ap0s7le.com>
 *         York Kie Tan / yktan <yktan@hotmail.com>
 * @package PHPLinkDirectory
 * @version 2.0.0 RC5.2
 **/

include '../../mainfile.php';
include(
XOOPS_ROOT_PATH '/header.php');
include(
"xoops_version.php"); 
$xoopsOption['template_main'] = 'submit.tpl';

require_once 
'init.php';

session_start();

//Evaluate payment options
if (PAY_ENABLE == '1' && PAYPAL_ACCOUNT != '') {
    
$price = array ();
    if (
FTR_ENABLE == '1' && PAY_FEATURED 0) {
        
$price['featured'] = PAY_FEATURED;
    }
    if (
PAY_NORMAL 0) {
        
$price['normal'] = PAY_NORMAL;
        if (
PAY_ENABLE_FREE) {
            
$price['free'] = 0;
        }
    }
    if (
PAY_RECPR 0) {
        
$price['reciprocal'] = PAY_RECPR;
    }
    
$xoopsTpl->assign('price'$price);

    if (isset (
$_REQUEST['LINK_TYPE'])) {
        
$link_type $_REQUEST['LINK_TYPE'];
        switch (
$link_type) {
            case 
'reciprocal' :
                
$recpr_required 1;
                break;
            case 
'free' :
                
$recpr_required REQUIRE_RECIPROCAL;
                break;
            default :
                
$recpr_required 0;
                break;
        }
    } else {
        
$recpr_required 0;
    }
    
$_SESSION['SmartyValidate']['submit_link']['validators'][6]['empty'] = $recpr_required 1;
    
$_SESSION['SmartyValidate']['submit_link']['validators'][7]['empty'] = $recpr_required 1;
} else {
    
$recpr_required REQUIRE_RECIPROCAL;
}
$xoopsTpl->assign('recpr_required'$recpr_required);
if (empty (
$_REQUEST['submit'])) {
    if (!empty (
$_SERVER['HTTP_REFERER']))
        
$_SESSION['return'] = $_SERVER['HTTP_REFERER'];
    
$cid get_category($_SERVER['HTTP_REFERER']);
    
$data = array ();
    
$data['CATEGORY_ID'] = $cid;
    
$data['RECPR_REQUIRED'] = $recpr_required;
    
SmartyValidate :: connect($xoopsTpl);
    
init_submission();
    
SmartyValidate :: register_form('submit_link'true);
    
SmartyValidate :: register_criteria('isValueUnique''validate_unique''submit_link');
    
SmartyValidate :: register_criteria('isNotEqual''validate_not_equal''submit_link');
    
SmartyValidate :: register_criteria('isURLOnline''validate_url_online''submit_link');
    
SmartyValidate :: register_validator('v_TITLE''TITLE''notEmpty'falsefalsefalse'trim''submit_link');
    
SmartyValidate :: register_validator('v_TITLE_U''TITLE:link:CATEGORY_ID''isValueUnique'falsefalsefalsenull'submit_link');
    
SmartyValidate :: register_validator('v_URL''URL''isURL'falsefalsefalse'trim''submit_link');
    
SmartyValidate :: register_validator('v_URL_ONLINE''URL''isURLOnline'falsefalsefalsenull'submit_link');
    
SmartyValidate :: register_validator('v_URL_U''URL:link::'. (ALLOW_MULTIPLE ':CATEGORY_ID' ''), 'isValueUnique'falsefalsefalsenull'submit_link');
    
SmartyValidate :: register_validator('v_CATEGORY_ID''CATEGORY_ID:0''isNotEqual'truefalsefalsenull'submit_link');
    
SmartyValidate :: register_validator('v_RECPR_URL''RECPR_URL''isURL', !$recpr_requiredfalsefalse'trim''submit_link');
    
SmartyValidate :: register_criteria('isRecprOnline''validate_recpr_link''submit_link');
    
SmartyValidate :: register_validator('v_RECPR_ONLINE''RECPR_URL''isRecprOnline', !$recpr_requiredfalsefalsenull'submit_link');
    
SmartyValidate :: register_validator('v_OWNER_NAME''OWNER_NAME''notEmpty'falsefalsefalse'trim''submit_link');
    
SmartyValidate :: register_validator('v_OWNER_EMAIL''OWNER_EMAIL''isEmail'falsefalsefalse'trim''submit_link');
    if(
count($price)>0){
        
SmartyValidate :: register_validator('v_LINK_TYPE''LINK_TYPE''notEmpty'falsefalsefalse'trim''submit_link');
    }
    if (
VISUAL_CONFIRM) {
        
SmartyValidate :: register_criteria('isCaptchaValid''validate_captcha''submit_link');
        
SmartyValidate :: register_validator('v_CAPTCHA''CAPTCHA''isCaptchaValid'falsefalsefalsenull'submit_link');
    }
} else {
    
SmartyValidate :: connect($xoopsTpl);
    
$data get_table_data('link');
    
$data['STATUS'] = 1;
    
$data['IPADDRESS'] = get_client_ip();
    
$data['VALID'] = 1;
    
$data['LINK_TYPE'] = $link_type;
    
$data['RECPR_REQUIRED'] = $recpr_required;
    if (
$recpr_required) {
        
$data['RECPR_VALID'] = 1;
        
$data['RECPR_LAST_CHECKED'] = gmdate('Y-m-d H:i:s');
    }

    if (
ENABLE_ID)
        
$data['RECPR_ID'] = $_SESSION['RECPR_ID'];

    
$data['LAST_CHECKED'] = gmdate('Y-m-d H:i:s');
    
$data['DATE_ADDED'] = gmdate('Y-m-d H:i:s');
    
$data['DATE_MODIFIED'] = gmdate('Y-m-d H:i:s');
    if (
strlen(trim($data['URL'])) > && !preg_match("`^http(s?)://`"$data['URL']))
        
$data['URL'] = "http://".$data['URL'];
    if (
strlen(trim($data['RECPR_URL'])) > && !preg_match("`^http(s?)://`"$data['RECPR_URL']))
        
$data['RECPR_URL'] = "http://".$data['RECPR_URL'];
    if (
VISUAL_CONFIRM) {
        
$data array_merge($data, array ('CAPTCHA' => $_REQUEST['CAPTCHA']));
    }
    if (
SmartyValidate :: is_valid($data'submit_link')) {
        if (
VISUAL_CONFIRM) {
            unset (
$data['CAPTCHA']);
        }
        if (
ENABLE_PAGERANK) {
            require_once 
'include/pagerank.php';
            
$data['PAGERANK'] = get_page_rank($data['URL']);
            if (!empty (
$data['RECPR_URL'])) {
                
$data['RECPR_PAGERANK'] = get_page_rank($data['RECPR_URL']);
            }
        }

        
$id $db->GenID($tables['link']['name'].'_SEQ');
        
$data['ID'] = $id;
        
$data['LINK_TYPE'] = $link_type_int[$link_type];
        switch(
$link_type){
            case 
'free':
                
$data['NOFOLLOW'] = 1;
                break;
            case 
'featured':
                
$data['FEATURED'] = 1;
                break;
        }
        
$data['OWNER_NOTIF'] = $price[$link_type] > 0?0:1;
        
$data['PAYED'] = $price[$link_type] > 0?0:-1;
        if (
$db->Replace($tables['link']['name'], $data'ID'true) > 0) {
            
$xoopsTpl->assign('posted'true);
            
send_submit_notifications($data);
            if(
$price[$link_type] > 0) { //Move to payment page
                
header("Location: payment.php?id=".$data['ID']);
                exit;
            }else{
                unset (
$data['TITLE']);
                unset (
$data['URL']);
                unset (
$data['DESCRIPTION']);
                unset (
$data['RECPR_URL']);

                if (
ENABLE_ID)
                    
init_submission();
            }
        } else {
            
$xoopsTpl->assign('error'true);
        }
    }
}
unset (
$_SESSION['CAPTCHA']);
$path = array ();
$path[] = array ('ID' => '0''TITLE' => _L(SITE_NAME), 'TITLE_URL' => DOC_ROOT'DESCRIPTION' => SITE_DESC);
$path[] = array ('ID' => '0''TITLE' => _L('Submit Link'), 'TITLE_URL' => '''DESCRIPTION' => _L('Submit a new link to the directory '));
$xoopsTpl->assign('path'$path);

if (
ENABLE_ID)
    
$xoopsTpl->assign('recpr_id'$_SESSION['RECPR_ID']);

$categs get_categs_tree($db0);
$xoopsTpl->assign('categs'$categs);
$xoopsTpl->assign($data);
$xoopsTpl->assign('LINK_TYPE'$link_type);
echo 
$xoopsTpl->fetch('submit.tpl'$id);

function 
validate_captcha($value$empty, & $params, & $form) {
    require_once 
'../../class/captcha/captcha.class.php';
    return isset (
$_SESSION['CAPTCHA']) && strtolower($_SESSION['CAPTCHA']) == strtolower($value);
}
function 
init_submission() {
    
mt_srand();
    
$_SESSION['RECPR_ID'] = mt_rand(00xFFFFFF);
}
$xoopsTpl->assign("xoops_module_header"'<link rel="stylesheet" type="text/css" href="module.css" />');
//echo $xoopsTpl->fetch('submit.tpl', $id);
include XOOPS_ROOT_PATH '/footer.php';
?>



submit.tpl
<{capture name="title"}> - Submit Link<{/capture}>
<{
capture assign="in_page_title"}>Submit Link<{/capture}>
<{
capture assign="description"}>Submit a new link to the directory<{/capture}>
<{include 
file="db:header.tpl"}>
<{include 
file="db:top_bar.tpl"}>

<{
strip}>
<{include 
file="admin/messages.tpl"}>

<
table border="0" class="formPage">
<{if 
$error}>
<
tr><td colspan="2" class="err">
An error occured while saving the link.
</
td></tr>
<{/if}>
<{if 
$posted}>
<
tr><td colspan="2" class="msg">
Link submitted and awaiting approval.<br />
Submit another link.
</
td></tr>
<{/if}>
<
form method="post" action="">
<{if 
count($price)>0}>
    <
tr><td colspan="2" class="price">
    <
b>Pricing:</b><br />
    <
table border="0" cellspacing="0" cellpadding="0">
    <{if 
$price.featured}>
        <
tr><td><input type="radio" name="LINK_TYPE" value="featured" <{if $LINK_TYPE eq 'featured'}>checked="true"<{/if}>>Featured links</td><td>$<{$price.featured}></td></tr>
    <{/if}>
    <{if 
$price.normal gt 0}>
        <
tr><td><input type="radio" name="LINK_TYPE" value="normal" <{if $LINK_TYPE eq 'normal'}>checked="true"<{/if}>>Regular links</td><td>$<{$price.normal}></td></tr>
    <{elseif 
$price.normal eq 0}>
        <
tr><td><input type="radio" name="LINK_TYPE" value="normal" <{if $LINK_TYPE eq 'normal'}>checked="true"<{/if}>>Regular links</td><td>free</td></tr>
    <{/if}>
    <{if 
$price.reciprocal gt 0}>
        <
tr><td><input type="radio" name="LINK_TYPE" value="reciprocal" <{if $LINK_TYPE eq 'reciprocal'}>checked="true"<{/if}>>Regular links with reciprocal</td><td>$<{$price.reciprocal}></td></tr>
    <{elseif 
$price.reciprocal eq 0}>
        <
tr>
          <
td><input type="radio" name="LINK_TYPE" value="reciprocal" <{if $LINK_TYPE eq 'reciprocal'}>checked="true"<{/if}>>Regular links with reciprocal</td>
          <
td>free</td></tr>
    <{/if}>
    <{if isset(
$price.free)}>
        <
tr><td><input type="radio" name="LINK_TYPE" value="free" <{if $LINK_TYPE eq 'free'}>checked="true"<{/if}>Links with nofollow attribute</td><td>free</td></tr>
    <{/if}>
    </
table>
    <{
validate form="submit_link" id="v_LINK_TYPE" message=$smarty.capture.field_link_type}>
    </
td></tr>
<{/if}>
  <
tr>
      <
td class="label"><span class='req'>*</span>Title:</td>
      <
td class="field">
          <
input type="text" name="TITLE" value="<{$TITLE}>" size="40" maxlength="100" class="text"/>
          <{
validate form="submit_link" id="v_TITLE" message=$smarty.capture.field_char_required}>
          <{
validate form="submit_link" id="v_TITLE_U" message=$smarty.capture.title_not_unique}>
      </
td>
  </
tr>
  <
tr>
      <
td class="label"><span class='req'>*</span>URL:</td>
      <
td class="field">
          <
input type="text" name="URL" value="<{$URL}>" size="40" maxlength="255" class="text"/>
          <{
validate form="submit_link" id="v_URL" message=$smarty.capture.invalid_url}>
          <{
validate form="submit_link" id="v_URL_ONLINE" message=$smarty.capture.url_not_online}>
          <{
validate form="submit_link" id="v_URL_U" message=$smarty.capture.url_not_unique}>
      </
td>
  </
tr>
  <
tr>
      <
td class="label">Description:</td>
      <
td class="field">
          <
textarea name="DESCRIPTION" rows="3" cols="37" class="text"><{$DESCRIPTION}></textarea>
      </
td>
  </
tr>
  <
tr>
      <
td class="label"><span class='req'>*</span>Your Name:</td>
      <
td class="field">
          <
input type="text" name="OWNER_NAME" value="<{$OWNER_NAME}>" size="40" maxlength="100" class="text"/>
          <{
validate form="submit_link" id="v_OWNER_NAME" message=$smarty.capture.field_char_required}>
      </
td>
  </
tr>
   <
tr>
      <
td class="label"><span class='req'>*</span>Your Email:</td>
      <
td class="field">
          <
input type="text" name="OWNER_EMAIL" value="<{$OWNER_EMAIL}>" size="40" maxlength="100" class="text"/>                  
      </
td>
  </
tr>
  <
tr>
      <
td class="label"><span class='req'>*</span>Category:</td>
      <
td class="field">
          <{
html_options options=$categs selected=$CATEGORY_ID name="CATEGORY_ID"}>
        <{
validate form="submit_link" id="v_CATEGORY_ID" message=$smarty.capture.no_url_in_top}>
      </
td>
  </
tr>
  <
tr>
      <
td class="label"><{if $recpr_required}><span class='req'>*</span><{/if}>Reciprocal Link URL:</td>
      <
td class="field">
          <
input type="text" name="RECPR_URL" value="<{$RECPR_URL}>" size="40" maxlength="255" class="text"/>
          <{
validate form="submit_link" id="v_RECPR_URL" message=$smarty.capture.invalid_url}>
<{if 
$recpr_required}>
          <{
validate form="submit_link" id="v_RECPR_ONLINE" message=$smarty.capture.recpr_not_found}>
<{/if}><
br />
        <
class="small">To validate the reciprocal link please include the<br />following HTML code in the page at the URL<br />specified abovebefore submiting this form:</p>
        <
textarea name="RECPR_TEXT" rows="2" readonly="true" cols="37" class="text"><a href="<{$smarty.const.SITE_URL}>"<{if $smarty.const.ENABLE_ID}> id="R<{$recpr_id|string_format:"%X"}>"<{/if}>><{$smarty.const.SITE_NAME}></a></textarea>
      </
td>
  </
tr>
<<{if 
$smarty.const.VISUAL_CONFIRM}>
  <
tr>
      <
td class="label"><span class='req'>*</span>Enter the code shown:</td>
      <
td class="field">
          <
input type="text" name="CAPTCHA" value="" size="10" maxlength="5" class="text"/>
        <{
validate form="submit_link" id="v_CAPTCHA" message=$smarty.capture.invalid_code}>
        <
br />
          <
class="small">This helps prevent automated registrations.</p>
          <
img src="<{$smarty.const.DOC_ROOT}>/captcha.php" class="captcha" />
      </
td>
  </
tr>
<{/if}>
  <
tr>
    <
td colspan="2" class="buttons"><input type="submit" name="submit" value="Continue" class="btn"/></td>
  </
tr>
</
form>
</
table>
<{include 
file="db:footer.tpl"}>
<{/
strip}>





Hope you can help me with this

1000 thanxxx in advance

cosmodrum