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

  • Home
  • SEARCH
  • 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 6133857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:16:55+00:00 2026-05-23T17:16:55+00:00

I have a very simple voting form. It contains a single text field for

  • 0

I have a very simple voting form. It contains a single text field for entry ID, then five dropdowns. The only validation being done is on the text field, but if it fails, I want all of the dropdowns to keep their values.

For example, a user enters 12345 as the entry, then selects option A from all five dropdowns. (Option B is default.) If 12345 fails validation, the dropdowns should still be set to option A when the validation error is displayed. That’s not happening. I’m using the form helper’s form_dropdown to create the dropdowns. Any ideas? As you can see, I tried using set_value on the dropdown called q1, but it doesn’t work. The validation itself does work.

Here’s the code for the form:

<?php
$hidden = array('dot_judge_id' => $this->session->userdata('dot_judge_id'));

echo form_open('vote/create'); 
$entry_code_data = array(
    'name' => 'entry_code',
    'id' => 'entry_code',
    'value' => set_value('entry_code')
);

echo form_hidden($hidden);

$score_options = array('1'=>'1 (lowest)', '2'=>'2','3'=>'3', '4'=>'4','5'=>'5 (highest)');
?>

<p><label for="entry_code">Entry code: </label><?php echo form_input($entry_code_data); ?></p>
<p><label for="q1">Question 1: </label><?php echo form_dropdown('q1', $score_options, set_value('q1')); ?></p>
<p><label for="q2">Question 2: </label><?php echo form_dropdown('q2', $score_options, ''); ?></p>
<p><label for="q3">Question 3: </label><?php echo form_dropdown('q3', $score_options, ''); ?></p>
<p><label for="q4">Question 4: </label><?php echo form_dropdown('q4', $score_options, ''); ?></p>
<p><label for="q5">Question 5: </label><?php echo form_dropdown('q5', $score_options, ''); ?></p>

<p><?php echo form_submit('submit', 'Submit vote'); ?></p>                

<?php echo form_close(); ?>
<?php echo validation_errors('<p class="error">', '</p>');?> 

I’ve had someone on the CodeIgniter forum tell me to use set_select, but I don’t think I can use set_select, because I’m not writing out the individual values of the select box, nor am I trying to provide a hard-coded default value. I need to reset the dropdowns to the values the user selected prior to running the form validation. I’m using the form_dropdown function, so how do I get the actual selected value to pass into the second param of set_select? According to the set_select documentation,

The first parameter must contain the name of the select menu, the
second parameter must contain the value of each item

There was also a comment on this post that said to use set_value –echo form_dropdown('events', $options, set_value('events'), $firstItem);. The comment got three votes, so I’m assuming that it works for some people, but doesn’t do anything for me. That question was a year old; perhaps that worked in an older version of CI but not the newest one. In any case, there HAS to be a way to have “sticky” dropdown values when creating dropdowns using form_dropdown, doesn’t there? I can’t imagine that I’d have to do it the long way and create the dropdown by looping through an array of values and echoing out each option line separately; that kind of defeats the purpose of using something like CI in the first place.

  • 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-23T17:16:56+00:00Added an answer on May 23, 2026 at 5:16 pm

    Remember that set_value() requires a second parameter that is the value of each item, so you can get this to work by adding $this->input->post('q1') as the second parameter.

    Instead of:

    <?php echo form_dropdown('q1', $score_options, set_value('q1')); ?>
    

    You would write:

    <?php echo form_dropdown('q1', $score_options, set_value('q1', $this->input->post('q1'))); ?>
    

    Hope that helps.

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

Sidebar

Related Questions

i have very simple problem. I need to create model, that represent element of
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding
I have a very simple bit of script that changes the status of an
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for
I have a very simple question. I want to test whether a particular port
I have some very simple code to generate an assembly and invoke a method

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.