Welcome Guest, Not a member yet? Register   Sign In
form_validation problem : don't work ??
#1

[eluser]ludo31[/eluser]
Hello ;

I never found whta's wrong with my code but I have form in view and in controller and I would like to validate the data but the message of error doesn't appear .

so my view is : folder views>annonce>annonce.php

and in annonce.php(view file )

Code:
<body>
    
   <?php echo validation_errors(); ?>
  
  
    <?php echo form_open_multipart('annonce/do_upload'); ?>
    
    <?php echo form_fieldset('Entana'); ?>
    
    <label for="titre" title="Titre">Lohateny (Titre) </label> <br>
  
    
        &lt;?php  echo form_error('titre', '<div class="error">', '</div>');  ?&gt;
    &lt;input type="text" name="titre" value="&lt;?php echo set_value('titre'); ?&gt;" size="50" /&gt;&lt;br/>

&lt;?php echo  form_submit('valider', 'Alefa'); ?&gt;
    
    
    
    
    &lt;?php echo  form_close(); ?&gt;
    
    
&lt;/body&gt;

in my controller :

Code:
class Annonce extends CI_Controller {

    
       public  function do_upload ()
{
      
       /* validation des donnees */
      
  
  
  


$this->form_validation->set_rules('titre', 'Titre', 'required');

if ($this->form_validation->run() == FALSE)
{
  $this->load->view('annonce/annonce_vue');
  

// echo 'non conforme '; exit ;
}
else
{
$this->load->view('annonce/annonce_vue');

// echo '  conforme '; exit ;
}
      


}

when I try echo 'non conforme '; exit ; instead of $this->load->view('annonce/annonce_vue'); it writes
Quote:non conforme

and in view file I try to make like this

Code:
&lt;?php echo form_input('titre', ''); ?&gt;
instead of

&lt;input type="text" name="titre" value="&lt;?php echo set_value('titre'); ?&gt;" size="50" /&gt;&lt;br/>

but the message of error doesn't appear !!
I load in config

Code:
$autoload['libraries'] = array('database','encrypt','pagination','session','cart','email','form_validation');


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('url','form','array','text','html','breadcrumb');

thanks
#2

[eluser]InsiteFX[/eluser]
In your view there are two ways to display validation errors.
Code:
// Setting error messages
$this->form_validation->set_message('rule', 'Error Message');

// one display all errors
&lt;?php echo validation_errors(); ?&gt;

// two display separate errors
<h5>Username</h5>
&lt;?php echo form_error('username'); ?&gt;
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;

#3

[eluser]ludo31[/eluser]
but I do that in my code !!

I found the problem ; form validation is only working in form_open() not form_open_multipart()
so I must create my own function for that and use callbacks

http://ellislab.com/codeigniter/user-gui...#callbacks




Theme © iAndrew 2016 - Forum software by © MyBB