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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:29:44+00:00 2026-05-29T17:29:44+00:00

First of all, I have already readed this: Validating form dropdown in CodeIgniter But

  • 0

First of all, I have already readed this: Validating form dropdown in CodeIgniter

But it doesnt solve my problem:

As you know, <option> value can be faked for example using firebug.

My select options looks like this:

<option value="ger">Germany</option>
<option value="uk">United Kingdom</option>
<option value="usa">United States of America</option>
[...]

Now, how can I validate if the choosen and posted value is correct?
These values are builded on the large array. It looks following:

$countries = array (
     'ger' => 'Germany',
     'uk'  => 'United Kingdom',
     'usa' => 'United States of America'
);

So how can I validate, of choosen value is correct? Will I have to use the array_key_exist with function callback on form validation?

What in case if my select options looks like this?

<option value="0">Choose Something</option>
<option value="1">Select-1</option>
<option value="2">Select-2</option>
[..]

How can I validate the above using the form validator, so I could check if the posted value is correct and not faked, also how to prevent from choosing the 0 value?

The best idea for this in my opinion is creating the function callback, which will look following:

public function validate_values($input)
{
      $allowed = array(1, 2, 3, 4); //[..]
      if ( !in_array( $input, $allowed ) )
      {
           //throw error, and do the rest...
      }

}

Are my ideas “ok” or there are any better solutions for these cases?

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

    The callback is exactly what you need. I think that’s why they were created. In user guide:

    “The validation system supports callbacks to your own validation
    functions. This permits you to extend the validation class to meet
    your needs.”

    So if your need is to check if submitted values are from defined range, use it.
    Of course it should return false or true depending on result. user guide for callbacks
    For me it’s the best solution. Especially because you need to check those values after form is submitted.

    As for preventing from choosing 0, don’t put 0 to in_array or check first if $input is !empty for example and set correct error message. If you’re creating your own callback you can validate that $input for whatever you want.

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

Sidebar

Related Questions

first of all I'm totally new to FAST but I already have a couple
First of all, I know how to build a Java application. But I have
First of all: I am not an experienced ClearCase user, but I have lots
First of all I don't know if it this question belongs here if not
I know some have already asked the question but so far, the answers are
First of all I know contenteditable is only iOS 5 I have accounted for
First of all, I have used ALL of the suggested methods in this SO
First of all i have to do this without IB and without advanced Objective-C
First of all I have to admit that my programming skills are pretty limited
So first of all I have such image (and ofcourse I have all points

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.