0

I have created a module, and I am trying to use the following code:

function mymodule_form_alter(&$form, &$form_state, $form_id) {     
  if ($form_state['view']->name == 'album1') {
    // ...
  }
  // ...
}

The line that causes the error is the following one:

if ($form_state['view']->name == 'album1') {

The error I get is the following one:

Notice: Trying to get property of non-object in mymodule_form_alter() (line 15 of C:\xampp\htdocs\drupal\sites\all\modules\mymodule\mymodule.module).

5

$form_state['view'] is not defined for all the forms, and it is not a value set by Drupal core modules. Before to access $form_state['view']->name you should verify $form_state['view'] is defined, and it is an object (and not an array, for example).

| improve this answer | |
  • but desired value i am getting from the variable.. – Hacker Sep 28 '11 at 16:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.