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

Smarty Validate IsFile

 
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 -> Add-ons
View previous topic :: View next topic  
Author Message
mjerom
Smarty Rookie


Joined: 09 Feb 2005
Posts: 9

PostPosted: Sat Feb 26, 2005 12:38 pm    Post subject: Smarty Validate IsFile Reply with quote

With the last CVS I cannot use the criteria IsFileType with empty="yes"

<input class="inputbox" name="vignette_news" type="file" size="32" maxlength="255" >
<br />
{validate form="news_form" field="file:vignette_news" empty="yes" criteria="isFileType" type="jpg, JPG, gif, GIF, png, PNG" message="File type not valid !"}

when I look at the $_POST array , I see
Array
(
[is_sent] => true
[titre_news] =>
[vignette] =>
[texte_news] =>
[lien_news] =>
[Submit] => OK
Arrow [file:vignette_news] => vignette_news
)

whereas this value was empty in the form !
Confused

thx
Back to top
View user's profile Send private message
mjerom
Smarty Rookie


Joined: 09 Feb 2005
Posts: 9

PostPosted: Tue Mar 01, 2005 12:36 pm    Post subject: Reply with quote

Am i missing something, I checked everything (as far as I can...)

my problem is that I need to make an upload form but this upload must be optional , I' m using this code :
Code:
<input class="inputbox" name="vignette_news" type="file" size="32" maxlength="255" >
<br />
{validate form="news_form" field="file:vignette_news" empty="yes" criteria="isFileType" type="jpg, JPG, gif, GIF, png, PNG" message="File type not valid !"}


but I always get the error message if the field is empty...
Sad

Thanks to help
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Mar 01, 2005 2:54 pm    Post subject: Reply with quote

It works fine for me. It is quite possible you forgot:

<form .... enctype="multipart/form-data">
</form>
Back to top
View user's profile Send private message Visit poster's website
mjerom
Smarty Rookie


Joined: 09 Feb 2005
Posts: 9

PostPosted: Tue Mar 01, 2005 3:57 pm    Post subject: Reply with quote

no I did not forgot the enctype...
Crying or Very sad

The thing is that is was working before upgrading validate with the CVS one.
I keep on investigating !
Back to top
View user's profile Send private message
mjerom
Smarty Rookie


Joined: 09 Feb 2005
Posts: 9

PostPosted: Sat Mar 05, 2005 7:33 am    Post subject: Reply with quote

Still not working for me ...
I really don't understand my problem !
here is the code I am using :

tpl :
Code:

<table class="adminheading" >
   <tr>
      <th class="modification_fiche">{$localisation}</th>
   </tr>
</table>
<table class="adminlist">
   <tr>
      <th align="center"> Remplissez le Formulaire</th>
   </tr>
</table>
<table class="adminform" >
   <form name="artiste_vignette_form" enctype="multipart/form-data" method="POST">
   <input type=hidden name='is_sent' value='true'>
   <tr>
      <td height="25" valign="middle">Vignette <br />.gif, .jpg ou .png</td>
      <td colspan="2">
         <input class="inputbox" name="vignette_artiste" type="file" size="32" maxlength="255" >
         <br />
         <FONT color="red">
               {validate form     = "artiste_vignette_form"
                         field    = "file:vignette_artiste"
                         criteria = "isFileType"
                         type     = "gif, GIF, jpg, JPG, png, PNG"
                         empty    = "yes"
                         message  = "La vignette n' est pas valide !"}
         </FONT>
      </td>
      <td>&</td>
   </tr>
   <tr>
      <td>&</td>
      <td colspan="2">
         <div align="left">
            <input class="button" type="submit" name="Submit" value="OK"></div>
      </td>
   </tr>
   </form>
</table>
<table class="adminlist">
   <tr>
      <th align="center"> * Obligatoire</th>
   </tr>
</table>


php:
Code:

SmartyValidate::connect($smarty);

      SmartyValidate::register_form('artiste_vignette_form');

      if(isset($_POST['is_sent']) && $_POST['is_sent'] == 'true') {

         if (isset($_GET['id_artiste'])) {

            $id_artiste = $_GET['id_artiste'];

         }
         
         if (SmartyValidate::is_valid($_POST,'artiste_vignette_form')) {

      
            $maj_artiste = new artiste ();

               
            // procedure d'upload
            $uniqid=uniqid(rand());
            $maj_artiste->vignette_artiste = $uniqid.".png";
               
            $upload = new upload ();
            $upload->nom_temporaire = $_FILES['vignette_artiste']['tmp_name'];
            $upload->nom_definitif  = "./images/artistes/".$uniqid.".png";
               
            $pathinfo  = pathinfo(realpath($HTTP_SERVER_VARS['PATH_TRANSLATED']));
            $upload->upload_img($pathinfo['dirname']."/", "tmp/".$uniqid);      
            

            $maj_artiste->mod_vignette_artiste();
      

            if($maj_artiste->id_artiste<>-1) {
            

               $affichage->localisation = "Artistes / upload / message";

               $affichage->titre        = "Merci";

                $affichage->message      = "Votre requête a &t& trait&e avec succès !";

               $affichage->message_type = "OK";

               $affichage->body         = "admin/page_message.html";

               SmartyValidate::disconnect();

                  
               $affichage->affichage_message ();

               exit;

               

            } else {

                  

               $affichage->localisation = "Artistes / upload / message";

               $affichage->titre        = "Problême";

                $affichage->message      = "Votre requête n'a pas &t& trait&e correctement !";

               $affichage->message_type = "pb";

               $affichage->body         = "admin/page_message.html";

               SmartyValidate::disconnect();

                  
               $affichage->affichage_message ();

               exit;

                  

            }

            

         }

      }

      

      /**

      *

      * Formulaire

      *

      */

      $affichage->localisation = "Artistes / upload";

      $affichage->body         = "admin/page_artiste_vignette_form.html";

      $affichage->affichage_page ();


If the field is empty I still get the error message...
I really tried to solve my problem but there is nothing I can do !

I am using the latest version of Smarty and Validate.

Can somebody help me please ?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Mar 05, 2005 4:57 pm    Post subject: Reply with quote

make sure you only call disconnect once, after the form is successfully complete. also only call is_valid right after the form submission, not before.
Back to top
View user's profile Send private message Visit poster's website
mjerom
Smarty Rookie


Joined: 09 Feb 2005
Posts: 9

PostPosted: Sat Mar 05, 2005 7:16 pm    Post subject: Reply with quote

I corrected my code :
Code:

      SmartyValidate::connect($smarty);

      SmartyValidate::register_form('artiste_vignette_form');

      

      if(empty($_POST)) {

      /**

      *

      * Formulaire

      *

      */

      $affichage->localisation = "Artistes / upload";

      $affichage->body         = "admin/page_artiste_vignette_form.html";

      $affichage->affichage_page ();

         
      } else {
      
         if (SmartyValidate::is_valid($_POST,'artiste_vignette_form')) {   
               
            if(!empty($_FILES['vignette_artiste']['name'])) {   
               // procedure d'upload
               $uniqid=uniqid(rand());
               $vignette_artiste = $uniqid.".png";
               
               $upload = new upload ();
               $upload->nom_temporaire = $_FILES['vignette_artiste']['tmp_name'];
               $upload->nom_definitif  = "./images/artistes/".$uniqid.".png";
               
               $pathinfo  = pathinfo(realpath($HTTP_SERVER_VARS['PATH_TRANSLATED']));
               $upload->upload_img($pathinfo['dirname']."/", "tmp/".$uniqid);      
            } else {
               $vignette_artiste = "NULL";
            }
            

            $maj_artiste = new artiste ();

            $maj_artiste->id_artiste = $_GET['id_artiste'];   

            $maj_artiste->vignette_artiste = $vignette_artiste;
            $maj_artiste->mod_vignette_artiste();

         
         
               

            if($maj_artiste->id_artiste<>-1) {

               

               $affichage->localisation = "Artistes / upload / message";

               $affichage->titre        = "Merci";

                $affichage->message      = "Votre requête a &t& trait&e avec succès !";

               $affichage->message_type = "OK";

               $affichage->body         = "admin/page_message.html";

               SmartyValidate::disconnect();

                  
               $affichage->affichage_message ();

               exit;

               

            } else {

                  

               $affichage->localisation = "Artistes / upload / message";

               $affichage->titre        = "Problême";

                $affichage->message      = "Votre requête n'a pas &t& trait&e correctement !";

               $affichage->message_type = "pb";

               $affichage->body         = "admin/page_message.html";

               //SmartyValidate::disconnect();

                  
               $affichage->affichage_message ();

               exit;

                  

            }

            

         } else {
            
            /**

            *

            * Formulaire

            *

            */

            $affichage->localisation = "Artistes / upload";

            $affichage->body         = "admin/page_artiste_vignette_form.html";

            $affichage->affichage_page ();
         }

      }


Still the same...
Sad
All my forms are validate driven and I have no problem ...
just when I add empty="yes" to a file field
Back to top
View user's profile Send private message
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 -> Add-ons 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