It is possible to set a Submit function for Preview button in an add/edit node form.

I would like to see if there is a possibility to go one step backward and validate the data to be previewed.

I just and only need to know how to have access to the validation hook for Preview button. (I don't need Submit hook! I only need Validate hook for this button)

2 Answers 2


There is no difference between Form Submit button's validate hook and Form Preview button's validate hook.

If you set the form's validate hook in HOOK_form_validate, you have set a secondary validation hook (it means if the default validation hook is passed, then it's the turn of the one you have set) which can be used for both Submit button and Preview button:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
   $form['#validate'][] = 'XYZ_validate';

Yes you can set the submit for the preview button.

You can find the which button is clicked in hook_node_validate() method.

 function custom_node_validate($node, $form, &$form_state) {
           $button_value = $form_state['clicked_button']['#value']; 
           if($button_value =="Preview"){
            //Do your stuff

It will give the clicked button value. For preview button you will get "Preview";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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