I am building an exposed filter dynamically. When the value is changed the ajax form callback is called to rebuild the form, but it gives error.

The form field to which the ajax callback is attached is a select field.. The error is

Call to a member function exposed_form_validate() on a non-object .

I have looked into the error and found that the

$exposed_form_plugin->exposed_form_validate($form, $form_state);

code is called on an object and $exposed_form_plugin is not being passed as an object. The variable gets its value from $form_state['exposed_form_plugin']. So i have induced that $form_state is definitely not an object. What am i doing wrong that the form_state is not being passed as object?

  • $form_state isn't supposed to be an object; it's the FAPI $form_state and will always be an array (see the code in views_plugin_exposed_filter::exposed_form_validate() as an example). Do you mean why is $form_state['exposed_form_plugin'] not an object? If so could you expand the question a bit to explain why you're expecting it to be an object, and add some more of you code in?
    – Clive
    Apr 11, 2013 at 9:44
  • $form_state is definitely an object becuase i have checked it in dump also $exposed_form_plugin->exposed_form_validate() shows that it is a n object becuase arrows are used with objects Apr 11, 2013 at 10:44
  • 1
    Sorry not sure what you mean by that. $form_state will always be an array, never an object. Check the link I provided in the last comment for an example straight from the views module itself. As you'll see, $form_state is accessed as an array, not an object. If you want to prove it just add an is_array($form_state) check in there somewhere. I guarantee it'll return TRUE
    – Clive
    Apr 11, 2013 at 10:46
  • @Clive: I meant to say that $form_state['exposed_form_plugin'] is not an object, the $form_state is an array no doubt but the value assigned to array index should be an object but it does not passes as on object when i do ajax rquest. Apr 15, 2013 at 12:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.