ninja_forms_preview_link

The Ninja Forms ninja forms preview link function.

Description

ninja_forms_preview_link( (string) $form_id = '', (bool) $echo = true ); 

Parameters (2)

0. $form_id — Optional. (string) => ''
The form id.
1. $echo — Optional. (bool) => true
The echo.

Usage

  1. if ( !function_exists( 'ninja_forms_preview_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/form-preview.php'; 
  3.  
  4. // The form id. 
  5. $form_id = ''; 
  6.  
  7. // The echo. 
  8. $echo = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_preview_link($form_id, $echo); 
  12.  

Defined (1)

The function is defined in the following location(s).

/deprecated/includes/admin/form-preview.php  
  1. function ninja_forms_preview_link( $form_id = '', $echo = true ) { 
  2. if( $form_id == '' ) { 
  3. if( isset( $_REQUEST['form_id'] ) ) { 
  4. $form_id = absint( $_REQUEST['form_id'] ); 
  5. }else{ 
  6. $form_id = ''; 
  7. $base = home_url(); 
  8.  
  9. $form_data = ninja_forms_get_form_by_id( $form_id ); 
  10.  
  11. $append_page = Ninja_Forms()->form( $form_id )->get_setting( 'append_page' ); 
  12.  
  13. if ( empty( $append_page ) ) { 
  14. $opt = nf_get_settings(); 
  15. if ( isset ( $opt['preview_id'] ) ) { 
  16. $page_id = $opt['preview_id']; 
  17. } else { 
  18. $page_id = ''; 
  19. } else { 
  20. $page_id = $append_page; 
  21.  
  22. if( $echo ) { 
  23. $preview_link = '<a target="_blank" href="' . $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id . '">' . __( 'Preview Form', 'ninja-forms' ) . '</a>'; 
  24. }else{ 
  25. $preview_link = $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id; 
  26.  
  27. return $preview_link; 
  28.