2010-11-14 9 views
0

J'ai un contrôleur qui charge la vue comme ceci: -Comment conserver les valeurs de formulaire?

class A extends Controller{ 
     public function simpleForm(){ 
      //this generates the form 
     } 

     public function simpleFormSubmitted(){ 
      //simple form is submitted here. Here i perform validation and if validation fails i 
//want to display simpleform again with all the values inputted by the user as it is and 
//if validation succeeds i want to redirect to some other page. 
// I am using simple HTML to generate the form and not the formhelper of codeigniter 
//because i am more comfortable with HTML rather than remembering the syntax of codeigniter. 
     } 
    } 

Merci à l'avance :)

Répondre

2

Voici comment préserver les champs de formulaire lorsqu'ils traitent des erreurs ...

$fields['username'] = 'Username'; 
$fields['password'] = 'Password'; 
$fields['passconf'] = 'Password Confirmation'; 
$fields['email'] = 'Email Address'; 

$this->validation->set_fields($fields); 

Voici comment repeupler le formulaire HTML ...

<?php echo $this->validation->error_string; ?> 

<?php echo form_open('form'); ?> 

<h5>Username</h5> 
<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" /> 

Pour plus d'informations ici regarder - Form Validation in Codeigniter Recherchez la rubrique Re-populating the form

0

en fonction SimpleForm ajouter des variables par défaut si, après validation, vous pouvez l'appeler à nouveau avec les valeurs userform

class A{ 
     public function simpleForm($val1="", val2="", $val3=""){ 
      //this generates the form 
     } 

     public function simpleFormSubmitted(){ 
      //simple form is submitted here. Here is perform validation and if validation fails i 
     if(!$valid){ 

      $result = $this->simpleForm($val1, $val2, $val3 etc...) 
     } 
     else{ 
     $result = //whatever you need to output after validation success 
     } 
     return $result 
     } 
    } 
Questions connexes