node_form_add_preview

Versions
4.7 – 5
node_form_add_preview($form)

Code

modules/node.module, line 1721

<?php
function node_form_add_preview($form) {
  global $form_values;

  $op = isset($_POST['op']) ? $_POST['op'] : '';
  if ($op == t('Preview')) {
    // Invoke full validation for the form, to protect against cross site
    // request forgeries (CSRF) and setting arbitrary values for fields such as
    // the input format. Preview the node only when form validation does not
    // set any errors.
    drupal_validate_form($form['form_id']['#value'], $form);
    if (!form_get_errors()) {
      // Because the node preview may display a form, we must render it
      // outside the node submission form tags using the #prefix property
      // (i.e. to prevent illegally nested forms).
      // If the node form already has a #prefix, we must preserve it.
      // In this case, we put the preview before the #prefix so we keep
      // the #prefix as "close" to the rest of the form as possible,
      // for example, to keep a <div> only around the form, not the
      // preview. We pass the global $form_values here to preserve
      // changes made during form validation.
      $preview = node_preview((object)$form_values);
      $form['#prefix'] = isset($form['#prefix']) ? $preview . $form['#prefix'] : $preview;
    }
  }
  if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
    unset($form['submit']);
  }
  return $form;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.