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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:15:18+00:00 2026-05-26T23:15:18+00:00

I am creating a wizard from the Drupal example file and would like to

  • 0

I am creating a wizard from the Drupal example file and would like to refactor the segments of code that are repeated when setting up items like options and radios.

I have already tried a simple function passing “ordinary” and “preferential” but can’t find a way to make it work.

Can someone give me an idea of the best way to do this?

unfactored code is as below:

function services_wizard_share_capital_classes($form, &$form_state) {

$form['share_classes']['type_of_class'] = array(
'#type' => 'select',
'#title' => t('What type of share will this class be?'),
'#options' => array(
  1 => t('Ordinary'),
  2 => t('Preferential'),
),
);

$form['ordinary']['share_type'] = array(
'#type' => 'item',
'#description' => t("You chose Ordinary Shares"),
'#states' => array(
  'visible' => array(
    ':input[name="type_of_class"]' => array('value' => '1'),
  ),
),
);

$form['preferential']['share_type'] = array(
'#type' => 'item',
'#description' => t("You chose Preferential Shares"),
'#states' => array(
  'visible' => array(
    ':input[name="type_of_class"]' => array('value' => '2'),
  ),
),
);
return $form;
}
  • 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-26T23:15:18+00:00Added an answer on May 26, 2026 at 11:15 pm

    I’m not sure about this being the best way but it’s certainly a way to refactor your code:

    function _services_wizard_share_capital_classes_add_el(&$form, $name, $description, $index) {
      $form[$name]['share_type'] = array(
        '#type' => 'item',
        '#description' => t($description),
        '#states' => array(
          'visible' => array(
            ':input[name="type_of_class"]' => array('value' => "$index"),
          ),
        )
      );
    }
    
    function services_wizard_share_capital_classes($form, &$form_state) {
      // Other code
    
      _services_wizard_share_capital_classes_add_el($form, 'ordinary', 'You chose Ordinary Shares', 1);
      _services_wizard_share_capital_classes_add_el($form, 'preferential', 'You chose Preferential Shares', 2);
      // etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to start the 'Scheduled Task Wizard' from the click of a button
I have a wizard that is responsible for creating 3 different types of resources.
I'm creating something like a wizard, and I'm using several User Control, but the
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I am trying to creating a small wizard using jsf1.2 sun RI +richfaces. The
I'm creating user controls that i will put into an update panel and make
I'm creating a wizard-based series of forms for taking user inputs. One of the
I am in the process of creating a Wizard to help my organization auto
I would like to remove some registry entries when my program is uninstalled. Is
The CoreData documentation says You can sometimes benefit from creating your own unique ID

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.