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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:05:20+00:00 2026-05-14T07:05:20+00:00

I’m writing a custom module and I’d like to use $form_state of the current

  • 0

I’m writing a custom module and I’d like to use $form_state of the current form in another non-form api function -> custom_facet_view_build().

any help is appreciated 🙂

<?php
/**
 * Implementation of hook_perm().
 */
function custom_facet_perm() {
  return array(
    'access foo content',
    'access baz content',
  );
}

/**
 * Implementation of hook_menu().
 */
function custom_facet_menu() {
  $items['faceted-search'] = array(
    'title' => 'Faceted Search',
    'page callback'    => 'drupal_get_form',
    'access arguments' => array(),
  );

  $items['facet-search-test'] = array(
    'page callback'    => 'drupal_get_form',
    'page arguments'   => array('custom_facet_form'),
    'access callback'  => TRUE,
    'type'             => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Form definition; ahah_helper_demo form.
 */
function custom_facet_form($form_state) {
  $form = array();

  ahah_helper_register($form, $form_state);

  if (isset($form_state['storage']['categories'])) {
    $categories_default_value = $form_state['storage']['categories']["#value"];
  }

  $form['facet_search_form'] = array(
    '#type'   => 'fieldset',
    '#title'  => t('Faceted Search'),
    '#prefix' => '<div id="billing-info-wrapper">', // This is our wrapper div.
    '#suffix' => '</div>',
    '#tree'   => TRUE, // Don't forget to set #tree!
  );

  $form['facet_search_form']['categories'] = array(
    '#type' => 'select',
    '#title' => t('Category'),
    '#options' => _custom_facet_taxonomy_query(1),
    '#multiple' => TRUE,
    '#default_value' => $categories_default_value,
  );

  $form['save'] = array(
    '#type'  => 'submit',
    '#value' => t('Save'),
  );

  return $form;
}

/**
 * Validate callback for the form.
 */
function custom_facet_form_validate($form, &$form_state) {

}

/**
 * Submit callback for the form.
 */
function custom_facet_form_submit($form, &$form_state) {
  drupal_set_message('nothing done');
  $form_state['storage']['categories'] = $form['facet_search_form']['categories'];
  // dpm($form_state); // There's a value returned in form_state['storage] within this function
}

/**
 * Implementation of hook_views_api().
 */
function custom_facet_views_api() {
  return array(
    'api' => 2,
  );
}

function custom_facet_view_build(&$view) {
    dpm($form_state); // form_state['storage] remains NULL even though there's a value on previous submission
}
  • 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-14T07:05:21+00:00Added an answer on May 14, 2026 at 7:05 am

    PHP functions are not aware of what variables that are in other functions.

    If the the functions are called in the same request cycle, you can store the $form_state variable in a global variable. Else you will need to store the variable in the db. That is the pain of HTTP, which is a stateless system.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT

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.