[SMARTY] Problems with SmartyValidate isFileType & isFileSize criteria

"Reynier Perez Mira" <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
Well, before post the message I check the Smarty forum looking for answers there. Only this thread I found: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=5785&highlight=smartyvalidate but it not works for me because I don't use SmartyValidate::register_form('my_form'). The case is that I need register two validators. One for verify if image type is correctly and the other for verify if file size is correctly or not. This is the code:

PHP:
---------
if(empty($_POST)) {
 SmartyValidate::connect($tpl, true);
 SmartyValidate::register_validator('fimagen_type','aImagen:jpg,gif,png','isFileType');
 SmartyValidate::register_validator('fimagen_size','aImagen:250k','isFileSize');
} else {
 SmartyValidate::connect($tpl);
 if(SmartyValidate::is_valid($_POST)) {
  SmartyValidate::disconnect();
   if ($step == "completar"){
   $query = $db->Execute("SELECT IDC FROM os_catproductos WHERE CNombre='".$_POST['aCategoria']."'"); 
   $aImg_tmp_name	= $_FILES['aImagen']['tmp_name'];
   $aImg_name = $_FILES['aImagen']['name'];
   $aImg_error = $_FILES['aImagen']['error'];
   if ($aImg_name != "") {
    $errores = array(UPLOAD_ERR_OK,UPLOAD_ERR_INI_SIZE,UPLOAD_ERR_FORM_SIZE,UPLOAD_ERR_PARTIAL,UPLOAD_ERR_NO_FILE,UPLOAD_ERR_NO_TMP_DIR,UPLOAD_ERR_CANT_WRITE);
    $imagen = preg_replace('/[- _]/X', '', $aImg_name);
    $categoria_name = str_replace(" ","", $_POST['aCategoria']);
    $img_rename = $idu . $categoria_name . $imagen; 
    $upload = move_uploaded_file( $aImg_tmp_name, UPLOAD_DIR . $img_rename );
    !$upload ? $tpl->assign('msg',$errores[$aImg_error]) : $sql = $db->Execute("INSERT INTO os_articulo (IDC,ANombre,ADescripcion,ACantidad,AImagen,IDU,APrecio) VALUES('".$query->fields['0']."','".$_POST['aNombre']."','".$_POST['aDescripcion']."','".$_POST['aCantidad']."','".$img_rename."','".$idu."','".$_POST['aPrecio']."')");
 } else {
  $sql = $db->Execute("INSERT INTO os_articulo (IDC,ANombre,ADescripcion,ACantidad,IDU,APrecio) VALUES('".$query->fields['0']."','".$_POST['aNombre']."','".$_POST['aDescripcion']."','".$_POST['aCantidad']."','".$idu."','".$_POST['aPrecio']."')");
 }
 !$sql ? $tpl->assign('msg', ERROR . MYSQL_MSG . $db->ErrorMsg()) : $tpl->assign('msg', ADD_OK);
 }
} else {
 $tpl->assign($_POST);
}
}

TPL:
---------
<input name="aImagen" type="file" id="aImagen" size="45" /> <div class="errormsg">{ validate id="fimagen_type" field="aImagen" message="Solo los siguientes tipos de extensiones son permitidos: PNG, JPG/JPEG, GIF"}{validate id="fimagen_size" field="aImagen" message="El peso de la imagen no puede exceder los 250kb"}</div>

I trim some code that's not necessary here for do the code more readable. When I send the form always this "notice" is returned:
Notice: Undefined index: aImagen in D:\Server\WWWRoot\ecommerce\smarty\SmartyValidate.class.php on line 225
Notice: Undefined index: aImagen in D:\Server\WWWRoot\ecommerce\smarty\SmartyValidate.class.php on line 225
Notice: Undefined index: aImagen in D:\Server\WWWRoot\ecommerce\smarty\SmartyValidate.class.php on line 241
Notice: Undefined index: aImagen in D:\Server\WWWRoot\ecommerce\smarty\SmartyValidate.class.php on line 255

And these are the validator error:
"Solo los siguientes tipos de extensiones son permitidos: PNG, JPG/JPEG, GIF" El peso de la imagen no puede exceder los 250kb

What's wrong here?

Regards
ReynierPM
4to. año Ing. Informática
Usuario registrado de Linux: #310201
*************************************************************************
El programador superhéroe aprende de compartir sus conocimientos. 
Es el referente de sus compañeros. Todo el mundo va a preguntarle y él, secretamente, lo fomenta porque es así como adquiere su legendaria
sabiduría: escuchando ayudando a los demás... 

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.