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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:36:03+00:00 2026-06-07T02:36:03+00:00

I am using a captcha in a form. When the user submits an invalid

  • 0

I am using a captcha in a form. When the user submits an invalid answer to the captcha, the page reloads repopulating the fields with the user data. My question is, is there a better (or easier) way to check which dropdown value was selected.

This is what I have now that works:

php

<?php
    $state = $sf_params->get('state'); 
?>

html

<span>State </span>
    <select size="1" name="state">
            <option value="" selected="selected"></option>
            <option value="AL" <?php if ($state == "AL") { echo "selected = 'selected'"; } ?>>Alabama</option>
            <option value="AK" <?php if ($state == "AK") { echo "selected = 'selected'"; } ?>>Alaska</option>
            <option value="AZ" <?php if ($state == "AZ") { echo "selected = 'selected'"; } ?>>Arizona</option>
            <option value="AR" <?php if ($state == "AR") { echo "selected = 'selected'"; } ?>>Arkansas</option>

Is there another solution to getting the GET variable, then parsing the options, looking for the matched value?

  • 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-06-07T02:36:05+00:00Added an answer on June 7, 2026 at 2:36 am

    First move the values of the select to an array in the Controller like

    $states = array('AL' => 'Alabama', ... );
    

    Then you can use the Helper j0k mentioned or go by feet:
    By assigning the vars in the controller.

    $this->states = $states;
    

    In the Template:

    <?php foreach ($states as $key => $value): ?>
    <option value="<?php echo $key ?>" <?php if ($state == $value) { echo "selected = 'selected'"; } ?>><?php echo $value ?></option>
    <?php endforeach; ?>
    

    But I also recommend to use the Helper.

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

Sidebar

Related Questions

Hi I'm using contact form 7 with Really Simple CAPTCHA, but it's throwing up
I have put a form on a web page where the user can send
Is there a simple captcha solution which can be easily integrated with a form
I'm looking at using an alternative to Captcha (or Recaptcha) for the registration form
i am using codeigniter . in my form i am using a captcha .
If you form has captcha (i'm using humanizer gem). How do you fill up
I'm used to using a standard form with JavaScript validation, custom captcha... etc. Now
I have a user registration form in PHP .I put captcha image check in
i am using iframe to refresh captcha whenever user makes an error in typing
I want to secure my form from spambots by using a captcha service. 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.