Support » Plugin: Gravity Forms WYSIWYG » [Plugin: Gravity Forms WYSIWYG] DefaultValue not working

  • Resolved reipan


    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Phil


    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
    		wp_editor($value, $input_id, $args);
    		$html = ob_get_contents();
    		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.

    Plugin Author bradvin


    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


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

    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.

    Plugin Author bradvin


    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Gravity Forms WYSIWYG] DefaultValue not working’ is closed to new replies.