Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7596533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:56:21+00:00 2026-05-30T21:56:21+00:00

Hi. I have the form in which I use form_validation If the user make

  • 0

Hi. I have the form in which I use form_validation If the user make any mistake (leave some required fields empty), user is redirected back to the form, and the form has been re-populated. All works, except my select , which is generated from the database.

Here is my code from the view:

echo "<select name='parentid'" . set_value("parentid"). ">";
echo '<option value = "0">None</option>';
foreach ($faq_categories as $row => $option) {
    echo "<option value=" . $option['catid'] . ">" . $option['categoryname']. "</option>";
}
echo '</select>';

Here is my controller code:

 public function displayAddFaqCategoryForm($error = null)
    {
        $data['title'] = "Add new FAQ Category";
        $data['main_content'] = 'addFaqCategory';
        $selectWhat = array('tname' => 'faq_categories',
                            'sortby'=> 'catid',
                            'how'   => 'asc'
                            );
        $this->load->model('selectRecords');
        $data['faq_categories'] = $this->selectRecords->selectAllRecords($selectWhat);
        $this->load->vars($data);
        $this->load->view('backOffice/template');
    } // end of function displayAddFaqCategoryForm 

And here is the model code:

 public function selectAllRecords($selectWhat = array())
    {
        $data = array();
        $tname = $selectWhat['tname'];
        $sortby = $selectWhat['sortby'];
        $how = $selectWhat['how'];
        $this->db->order_by($sortby,$how);
        $query = $this->db->get($tname);
        if($query->num_rows() > 0) 
        {
            foreach($query->result_array() as $row) 
            {
                $data[] = $row;  
            }
        }
        $query->free_result();
        return $data;
    } // end of function selectAllRecords 

I am not getting any error messages, just the select is not repopulated with last used. Any help will be deeply appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:56:22+00:00Added an answer on May 30, 2026 at 9:56 pm

    You’re using set_value() incorrectly

    echo "<select name='parentid'" . set_value("parentid"). ">";
    

    It’s meant to output the actual value (for text inputs). This would produce something like:

    <select name='parentid'ActualValue>
    

    Which is not how a <select> element is populated, and is invalid HTML. See the correct usage in the Form Helper docs.

    You can use set_select(), and it goes on your <option>:

    foreach ($faq_categories as $row => $option) {
    
        echo "<option value=".form_prep($option['catid']).'"';
    
        echo set_select('parentid', $option['catid']); // outputs selected="selected"
    
        echo ">".html_escape($option['categoryname'])."</option>";
    }
    

    I’ve taken a few other liberties with your code here as you can see, to be on the safe side (always).

    If this is too much of a mess, you might be interested in the form_dropdown() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a form which a user can use to create a new
I have a page which displays a form that a logged-in user can use
I am trying to use a textarea form entry which I have some javascript
I have a form which permits updating of a user record. It contains fields
I have a multi-step form in which some of the fields are collecting sensitive
I have a form which takes both the user details and an image uploaded
I have a form, on which I have a button - When the user
I have a form with many input fields on it, some with validation. I
I have a Drupal 7 form which I'm allowing the user to submit via
I have a form which is used to insert/display and update . In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.