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 6859909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:33+00:00 2026-05-27T02:20:33+00:00

Obivously, I have 2 problems. When I submit a checkbox form which is an

  • 0

Obivously, I have 2 problems.

  1. When I submit a checkbox form which is an array value and non-cheched form, It doesn’t show me validation error such as ‘this field is required’. It shows error when I check one of them. Normally it should have shown me even though I don’t check anything on the form and just press submit.

  2. How can I repopulate a checkbox as checked when I submit as checked. Think like set_value. In set_value it populates previous data. At this I want it to be auto checked when if I had submitted.

My controller

function preferences() {
    $user = $this->ion_auth->user()->row();
    $data['first_name'] = $user->first_name;
    $data['last_name'] = $user->last_name;
    $data['user_id'] = $user->id;
    $data['address'] = $this->main_model->office_zip_match($user->zipcode);

    $this->form_validation->set_rules('days[]', 'Days', 'required');
    $this->form_validation->set_rules('contact[]', 'Contact', 'required');

    if ($this->form_validation->run() == true) {
        echo print_r($this->input->post());
    } else {
        $this->load->view('auth/preferences', $data);
    }
}

My view:

<div>Days to Deliver</div>
<?php echo form_open('signup/preferences'); ?>
<input type="checkbox" name="days[]" value="monday" id="days" /> Monday<br />
<input type="checkbox" name="days[]" value="tuesday" id="days" /> Tuesday<br />
<input type="checkbox" name="days[]" value="wednesday" id="days" /> Wednesday<br />
<input type="checkbox" name="days[]" value="thursday" id="days" /> Thursday<br />
<input type="checkbox" name="days[]" value="friday" id="days" /> Friday<br />
<div>How would you like us to contact you? (When package arrives / for all other issues</div>
<input type="checkbox" name="contact[]" value="email" id="contact" /> Email<br />
<input type="checkbox" name="contact[]" value="text" id="contact" /> Text<br />
<input type="checkbox" name="contact[]" value="cell" id="contact" /> Cell<br />
<div><input type="submit" value="Send" /></div>
<?php echo form_close(); ?>
<?php echo validation_errors(); ?>
  • 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-27T02:20:33+00:00Added an answer on May 27, 2026 at 2:20 am

    Firstly; validate your checkbox using a custom callback, you can do whatever you want to validate the contents.

    Secondly; use an if to set the checked=”checked”.

    $my_option_values is a hash array of the checkbox options.

    <input type="checkbox" name="my_option[]" value="blah" 
    <?php ( in_array('blah', $_POST['my_option']) || in_array('blah', $my_option_values) ) ? print 'checked="checked"' : FALSE; ?> />
    

    If you want, make it a function and put it in a helper file.

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

Sidebar

Related Questions

I have a bit of a conundrum. I have a form which has numerous
I have a web application which is used by lots of non-technical users. I
I have a form, on which I have a button - When the user
I have a dynamically generated form that I would like to submit using Ajax.
I have a global form which I want to use the same form every
i have problems with ajax requests and simple <input type=submit/> . i use to
I have a symfony 1.4 form with 2 embedded forms. The parent form has
Having problems with IE8... I have a button that onclick fires the showImageBrowser() function.
I am submitting from a form to another php page which is supposed to
I have serious problems since I migrated my core data logic to RKManagedObjectStore. I

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.