[eluser]Salim[/eluser]
Hi all,
I have a persistent problem from many days ... and i have not found any answer in the forum.
I have the following form inside my view file. There is :
- 3 select
- 2 radio button
- 1 input text
All of them are passed to a validation process in the associated controller:
View File:
Code:
<form action="<?=base_url();?>index.php/registration/step3" method="post">
<?php if ($this->validation->day_error <> "") {?>
<div id="avertissement_red"><?php echo $this->validation->day_error ?></div>
<?php } ?>
<?php if ($this->validation->month_error <> "") {?>
<div id="avertissement_red"><?php echo $this->validation->month_error ?></div>
<?php } ?>
<?php if ($this->validation->year_error <> "") {?>
<div id="avertissement_red"><?php echo $this->validation->year_error ?></div>
<?php } ?>
<p>Ta date de naissance :
<select name="day" >
<option value='Jour' <?php $this->validation->set_select('day', 'Jour'); ?> >Jour</option>
<option value='31' <?php $this->validation->set_select('day', '31'); ?> >31</option>
<option value='30' <?php $this->validation->set_select('day', '30'); ?> >30</option>
</select>
<select name="month">
<option value='Mois' <?php $this->validation->set_select('month', 'Mois'); ?>>Mois</option>
<option value='12' <?php $this->validation->set_select('month', '12'); ?> >12</option>
<option value='11' <?php $this->validation->set_select('month', '11'); ?> >11</option>
<option value='10' <?php $this->validation->set_select('month', '10'); ?> >10</option>
<option value='09' <?php $this->validation->set_select('month', '09'); ?> >09</option>
<option value='08' <?php $this->validation->set_select('month', '08'); ?> >08</option>
<option value='07' <?php $this->validation->set_select('month', '07'); ?> >07</option>
<option value='06' <?php $this->validation->set_select('month', '06'); ?> >06</option>
<option value='05' <?php $this->validation->set_select('month', '05'); ?> >05</option>
<option value='04' <?php $this->validation->set_select('month', '04'); ?> >04</option>
<option value='03' <?php $this->validation->set_select('month', '03'); ?> >03</option>
<option value='02' <?php $this->validation->set_select('month', '02'); ?> >02</option>
<option value='01' <?php $this->validation->set_select('month', '01'); ?> >01</option>
</select>
<select name="year">
<option value='Annee' <?php $this->validation->set_select('year', 'Annee'); ?>>Année</option>
<option value='2000' <?php $this->validation->set_select('year', '2000'); ?>>2000</option>
<option value='1999' <?php $this->validation->set_select('year', '1999'); ?>>1999</option>
<option value='1998' <?php $this->validation->set_select('year', '1998'); ?>>1998</option>
<option value='1997' <?php $this->validation->set_select('year', '1997'); ?>>1997</option>
<option value='1996' <?php $this->validation->set_select('year', '1996'); ?>>1996</option>
<option value='1995' <?php $this->validation->set_select('year', '1995'); ?>>1995</option>
</select>
</p>
<?php if ($this->validation->sexe_error <> "") {?>
<div id="avertissement_red"><?php echo $this->validation->sexe_error ?></div>
<?php } ?>
<p>Tu es : une femme <input name="sexe" type="radio" value="2" <?php echo $this->validation->set_radio('sexe', '2'); ?>/> ou un homme <input name="sexe" type="radio" value="1" <?php echo $this->validation->set_radio('sexe', '1'); ?>/></p>
<p>Télécharge ta photo : <input name="photo" type="text" value=""/></p>
<p><input type="submit" value="Aller à l'étape 4" /></p>
</form>
Controller File
Code:
function step3 ()
{
$rules['day'] = "trim|callback_day_check";
$rules['month'] = "trim";
$rules['year'] = "trim";
$rules['sexe'] = "trim|required|callback_sexe_check";
$fields['day'] = 'Jour';
$fields['month'] = 'Mois';
$fields['year'] = 'Année';
$fields['sexe'] = 'Homme/Femme';
$data['title'] = "Registration page - Step3";
$data['heading'] = "";
$this->validation->set_fields($fields);
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
$this->load->view('Registration/step3', $data);
}
else {
$this->step4();
}
}
The validation process work fine, and all my rules are fully respected.
The probleme i have is that my select lists posted data are not saved if one of the others filled have an error during the validation.
For example, if i correctly choose a day / month / year, without choosing one of the 2 radio button, The error message for the missing radio button appears but all of my lists don't display the previous selected data...
Does anyone have a solution please ....