Search code examples
codeignitervalidationrepopulation

How do I repopulate fields BEFORE validation is passed?


The fields I am making required to fill out, should repopulate the correctly filled out fields, while NOT submitting the form and posing errors for the incorrectly filled out fields. What is the best way to do that?

Please note that with this code, I am repopulating the fields as they should be upon submitting the form correctly and they are all displaying when page is reloaded.

    <div class="dropdown_structure">
        <?php

        if($user['location'] == "empty")
        {
        echo country_dropdown('location');

        }
        else
        {
        echo country_dropdown('location',$user['location']);

        }

        ?>
  </div>

Also please note that I've tried inserting the value in the input fields.

$data = array( 'name' => 'location', 'value' => $this->input->post('location'));
echo relation_dropdown('location');

Thanks in advance


Solution

  • Hi if you are using the following country dropdown helper you can set value validation in following way

    Country dropdown helper

    country_dropdown('location',array(),set_value('location'))
    

    even in your second dropdown use set_value('field_name') will work. if validation is failed your selected value will be remain.