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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:46:16+00:00 2026-05-12T22:46:16+00:00

I am using the widget sfWidgetFormChoice(array ( ‘choices’ => CountryPeer::getAllCountry(), )) and validator as

  • 0

I am using the widget

sfWidgetFormChoice(array (
  'choices' => CountryPeer::getAllCountry(),
))

and validator as

sfValidatorChoice(array (
  'choices' => array_keys(CountryPeer::getAllCountry()),
))

I get a select element as

<select id="country" name="reg_form[country]">
  <option value="1">India</option>
  <option value="2">Srilanka</option>
</select>

I want to add a option --Select Countries-- as default:

<option value="">--Select Countries--</option>

so that it should throw an required error, if i am not selecting any country.

  • 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-12T22:46:16+00:00Added an answer on May 12, 2026 at 10:46 pm

    First, add the option to the array of choices, but not into the validator, so it will throw the error:

    $def_val = array(-1=>"--Select Countries--");
    
    $sel_choices = array_merge($def_val,CountryPeer::getAllCountry());
    
    sfWidgetFormChoice(array (
      'choices' => $sel_choices,
    ))
    
    sfValidatorChoice(array (
      'choices' => array_keys(CountryPeer::getAllCountry()),
    ))
    

    And then set the “-1” option as the default value:

     $your_form->setDefault('country', -1);
    

    Should do it.

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

Sidebar

Related Questions

I'm using a sfWidgetFormSelect widget to render a select list. More precisely i'm using
i am using this widget to get my users to create accounts: <iframe src=http://www.facebook.com/plugins/registration.php?
I am using AutoComplete widget. It works fine for two characters search but doesen't
I need to create a rectangle in a Canvas widget using the background color
Im using an existing widget from the jquery-ui labs call selectmenu. It has callback
i deserialize a widget-hierarchy using gson, but have problems deserializing final fields. Example: public
Actually I created a button using the cobogw widget library. But the button does
In ma application I am using a gallery widget having an ImageView and a
I have a selection for some items using a spinner widget. At the moment
I'm working on a first symfony project, i am using the sfWidgetFormTextareaTinyMCE widget for

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.