Thursday 15 March 2012

Drupal 7 & PHP - display content if $form is any Content Type -


I need help in making an I statement which will cancel the cancel button as only in the form of nodes Will print Without a statement, the Cancel button is printed on all forms, including the site search form. I '$ form_id! = ', But adding every form ID where I do not want no to cancel the button does not look very smooth, any help would be greatly appreciated.

  & lt ;? Php / ** * Impressions hook_form_alter () * / function cancel_button_form_alter (& amp; $ form, & amp; $ form_state, $ form_id) {// Here's the problem I'm having the variable // I Can I put the contents of it? If ($ form_id! = 'Search_block_form') {// Add Cancel button. $ Form ['actions'] ['Cancel'] = Array ('#type' = & gt; 'submit', '#value' = & gt; t ('cancel'), '#AC' = & Gt; TRUE, # weight '=> 15,' #submit '=> array (' cancel_buttons_con_connect ',' node_form_submit_built_net '),' #limit_validation_errors' => array (),); }} / ** * Custom Cancel button callback * / function cancel_button_form_cancel ($ form, and $ form_state) {$ url = $ _GET ['Destination']? $ _GET ['Destination']: ''; Drupal_goto ($ url); If you are in a node / content, then  $ form     

The variable will have a node object but if the node is not for / node then it will not have node object. You can check it like this:
  if (isset ($ form ['# node'])) {// your code goes here}   < P> Actually, I have some confusion about the  $ form ['# node']  (: P). You can get it by debuging  $ form  or  $ form_state  variable   

No comments:

Post a Comment