WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms WYSIWYG
[resolved] DefaultValue not working (6 posts)

  1. reipan
    Member
    Posted 2 years ago #

    hey folks,
    first of all thx for your great plugin. There is just one thing, which keeps me from using it. In order to allow a user to edit some texts, i need to prepoluate the wysiwyg-field. Assigning the text to the 'defaultValue' attribute doesnt work like on every other gravityforms field. Maybe someone has experienced the same issue and can provide some assistance.

    regards, bene.

    http://wordpress.org/extend/plugins/gravity-forms-wysiwyg/

  2. Phil
    Member
    Posted 1 year ago #

    I came across the same issue and welcome corrections/feedback to the approach below. In addition to fully enabling GF's dynamic population, this appears to be an alternative resolution to the problem of wysiwyg field content not being retained when validation fails, discussed here. It could also be an opportunity to incorporate the wp media button, as discussed here.

    Because we'll replace the functionality of the wysiwyg_enqueue_scripts() function elsewhere, comment out line 27 in the file gf_wysiwyg_class.php:

    // add_action( 'gform_enqueue_scripts' , array(&$this, 'wysiwyg_enqueue_scripts') , 10 , 2 );

    For good measure, comment out the entire associated wysiwyg_enqueue_scripts() function starting on line 105. We'll insert its functionality into the wysiwyg_field_input() function where we have access to the $value parameter we'll pass to the wp_editor() function for dynamic population. Go ahead and replace the entire wysiwyg_field_input() function (starts on line 67) with this:

    function wysiwyg_field_input( $input, $field, $value, $lead_id, $form_id ) {
      if ( $this->is_wysiwyg($field) ) {
    
    	$input_id = 'input_' . $form_id . '_' . $field["id"];
    
    	if (is_admin()) {
    
    	  $tabindex = GFCommon::get_tabindex();
    	  return sprintf("<div class='ginput_container'><textarea readonly name='input_%s' id='input_%s' class='textarea gform_wysiwyg' {$tabindex} rows='10' cols='50'>WYSIWYG editor</textarea></div>", $field["id"], 'wysiwyg-'.$field['id']);
    
    	} else {
    
    		$args = array(
    			'textarea_name' => 'input_'.$field["id"],
    			'wpautop' => true,
    			'media_buttons' => false, // possibly true
    			'editor_class' => 'frontend',
    			'textarea_rows' => 5,
    			'tabindex' => 0 //$tabindex
    		);          
    
    		ob_start();
    		wp_editor($value, $input_id, $args);
    		$html = ob_get_contents();
    		ob_end_clean();
    
    		return "<div class='ginput_container'>" . $html . "</div>";
    	}
    
      }
    
      return false;
    }

    I tested the above with WP v3.4.2, GF v1.6.10, and GF + WYSIWYG v0.1 beta. It works for me with all methods of dynamic population I'm aware of (query string, shortcode, hooks, $field_values parameter of gravity_form() function, and "Default Value" set for field in the form editor in the admin).

    Obviously, you'll want to test it fully before using on your production site. As time permits, maybe the plugin author will comment on whether this breaks something and whether it fits with the rest of the code conceptually.

  3. bradvin
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Phil

    Thanks so much for the code - I am looking at updating this plugin in the next week and will fully test and incorporate your code accordingly

    cheers
    Brad

  4. Kevin Ryman
    Member
    Posted 1 year ago #

    Thanks Phil! Any news on the update, Brad? :]

  5. nahyanshiwani
    Member
    Posted 1 year ago #

    How can we auto-fill the wysiwyg-field when editing a post from front-end?
    For other GF fields there is a checkbox to allow field to be populated dynamically with shortcodes or hooks.

  6. bradvin
    Member
    Plugin Author

    Posted 1 year ago #

    Hey all - I have updated the plugin to use a modified variation of this code

    V0.2 beta now fixes a couple bugs and also adds support for enabling the media buttons

    thanks again to Phil for posting his code

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic