Custom redirect for form-edit displayed in Views header I have a content type called 'Checklist' which I bring forward using Views, in it's node-edit form.

I wrote PHP code within the header in order to do this, here it is:

&lt;?php 

    $view = views_get_current_view();
    $arg0 = $view-&gt;args[0];

    $nodeToLoad = $view-&gt;result[0]-&gt;nid; //I get the node to load from Fields within my view
    module_load_include('inc', 'node', 'node.pages');

    $node = node_load($nodeToLoad);
    dsm($nodeToLoad);
    $edit_page = drupal_get_form('page_node_form', $node);

    $edit_page['additional_settings']['#access'] = FALSE;
    $edit_page['buttons']['submit']['#submit'][] = 'redirect_submit';
    print drupal_render($edit_page );

    function redirect_submit($form, &amp;$form_state){
        $form_state['redirect'] = 'www.google.com';
    }
?&gt;


Now what I want is to add a custom redirect upon saving this particular form.

I've tried this to no avail:

    $edit_page['buttons']['submit']['#submit'][] = 'redirect_submit';
    print drupal_render($edit_page );

    function redirect_submit($form, &amp;$form_state){
        $form_state['redirect'] = 'www.google.com';
    }


Is it possible to this within the Views header?



Notes: 


I have also done this with the Rules module but I'd like to learn
if it's possible to do with PHP code in the Views header so I don't
split functionality in 2 parts of my project.
This can also be easily done using a custom hook but again, if it's
possible to do this within the Views header then that's the trick I'm looking
for.


Thanks.
You could to use hook_form_FORM_ID. Something like this:

function mymodule_form_page_node_form_ater(&amp;$form, &amp;$form_state, $form_id){
   if(current_path() == 'page/where/my/view/is'){
     $form_state['redirect'] = 'page/to/redirect';
   }
}


If you don't want to use a hook, you can do something like this:

 $edit_page['buttons']['submit']['#submit'][] = 'redirect_submit';


Then,

 function redirect_submit($form, &amp;$form_state){
  $form_state['redirect'] = 'path/to/rediect';
 }


Still it is bad practice to inlcude php in your views header. You should implement a custom area handler.


How to create a view area handler
https://api.drupal.org/api/views/handlers!views_handler_area.inc/group/views_area_handlers/7
https://oliverhuynh.wordpress.com/2011/06/23/custom-views-handler-drupal-7-template/