Welcome Guest, Not a member yet? Register   Sign In
Problem with set_select( ) function - CI Validation Class
#1

[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">
     &lt;?php if ($this->validation->day_error <> "") {?&gt;
    <div id="avertissement_red">&lt;?php echo $this->validation->day_error ?&gt;</div>
    &lt;?php } ?&gt;
    &lt;?php if ($this->validation->month_error <> "") {?&gt;
    <div id="avertissement_red">&lt;?php echo $this->validation->month_error ?&gt;</div>
    &lt;?php } ?&gt;
    &lt;?php if ($this->validation->year_error <> "") {?&gt;
    <div id="avertissement_red">&lt;?php echo $this->validation->year_error ?&gt;</div>
    &lt;?php } ?&gt;
    <p>Ta date de naissance :
    <select name="day" >
    <option value='Jour' &lt;?php $this->validation->set_select('day', 'Jour'); ?&gt; >Jour</option>
        <option value='31' &lt;?php $this->validation->set_select('day', '31'); ?&gt; >31</option>
        <option value='30' &lt;?php $this->validation->set_select('day', '30'); ?&gt; >30</option>
    </select>
    <select name="month">
    <option value='Mois' &lt;?php $this->validation->set_select('month', 'Mois'); ?&gt;>Mois</option>
        <option value='12' &lt;?php $this->validation->set_select('month', '12'); ?&gt; >12</option>
        <option value='11' &lt;?php $this->validation->set_select('month', '11'); ?&gt; >11</option>
        <option value='10' &lt;?php $this->validation->set_select('month', '10'); ?&gt; >10</option>
        <option value='09' &lt;?php $this->validation->set_select('month', '09'); ?&gt; >09</option>
        <option value='08' &lt;?php $this->validation->set_select('month', '08'); ?&gt; >08</option>
        <option value='07' &lt;?php $this->validation->set_select('month', '07'); ?&gt; >07</option>        
        <option value='06' &lt;?php $this->validation->set_select('month', '06'); ?&gt; >06</option>
        <option value='05' &lt;?php $this->validation->set_select('month', '05'); ?&gt; >05</option>
        <option value='04' &lt;?php $this->validation->set_select('month', '04'); ?&gt; >04</option>
        <option value='03' &lt;?php $this->validation->set_select('month', '03'); ?&gt; >03</option>
        <option value='02' &lt;?php $this->validation->set_select('month', '02'); ?&gt; >02</option>
        <option value='01' &lt;?php $this->validation->set_select('month', '01'); ?&gt; >01</option>
    </select>
    <select name="year">
        <option value='Annee' &lt;?php $this->validation->set_select('year', 'Annee'); ?&gt;>Ann&eacute;e</option>
        <option value='2000' &lt;?php $this->validation->set_select('year', '2000'); ?&gt;>2000</option>
        <option value='1999' &lt;?php $this->validation->set_select('year', '1999'); ?&gt;>1999</option>
        <option value='1998' &lt;?php $this->validation->set_select('year', '1998'); ?&gt;>1998</option>
        <option value='1997' &lt;?php $this->validation->set_select('year', '1997'); ?&gt;>1997</option>
        <option value='1996' &lt;?php $this->validation->set_select('year', '1996'); ?&gt;>1996</option>
        <option value='1995' &lt;?php $this->validation->set_select('year', '1995'); ?&gt;>1995</option>
    </select>

    </p>
    &lt;?php if ($this->validation->sexe_error <> "") {?&gt;
    <div id="avertissement_red">&lt;?php echo $this->validation->sexe_error ?&gt;</div>
&lt;?php } ?&gt;
    <p>Tu es : une femme &lt;input name="sexe" type="radio"  value="2" &lt;?php echo $this-&gt;validation->set_radio('sexe', '2'); ?&gt;/> ou un homme &lt;input name="sexe" type="radio"  value="1"  &lt;?php echo $this-&gt;validation->set_radio('sexe', '1'); ?&gt;/></p>
    <p>Télécharge ta photo : &lt;input name="photo" type="text"  value=""/&gt;</p>
    <p>&lt;input type="submit" value="Aller à l'&eacute;tape 4" /&gt;</p>
&lt;/form&gt;

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&eacute;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 ....


Messages In This Thread
Problem with set_select( ) function - CI Validation Class - by El Forum - 05-15-2008, 06:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB