Guest User

Untitled

a guest
Jul 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. function node_form_add_preview($form) {
  3. global $form_values;
  4.  
  5. $op = isset($form_values['op']) ? $form_values['op'] : '';
  6. if ($op == t('Preview')) {
  7. // Invoke full validation for the form, to protect against cross site
  8. // request forgeries (CSRF) and setting arbitrary values for fields such as
  9. // the input format. Preview the node only when form validation does not
  10. // set any errors.
  11. drupal_validate_form($form['form_id']['#value'], $form);
  12. if (!form_get_errors()) {
  13. // Because the node preview may display a form, we must render it
  14. // outside the node submission form tags using the #prefix property
  15. // (i.e. to prevent illegally nested forms).
  16. // If the node form already has a #prefix, we must preserve it.
  17. // In this case, we put the preview before the #prefix so we keep
  18. // the #prefix as "close" to the rest of the form as possible,
  19. // for example, to keep a <div> only around the form, not the
  20. // preview. We pass the global $form_values here to preserve
  21. // changes made during form validation.
  22. $preview = node_preview((object)$form_values);
  23. $form['#prefix'] = isset($form['#prefix']) ? $preview . $form['#prefix'] : $preview;
  24. }
  25. }
  26. if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
  27. unset($form['submit']);
  28. }
  29. return $form;
  30. }
Add Comment
Please, Sign In to add comment