Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Last active May 30, 2018 03:22
Show Gist options
  • Save kjohnson/ff8ff732b42173c1f49aaa4cd62c8f80 to your computer and use it in GitHub Desktop.
Save kjohnson/ff8ff732b42173c1f49aaa4cd62c8f80 to your computer and use it in GitHub Desktop.
<?php
// apply_filters('ninja_forms_render_default_value', $default_value, $field_type, $feild_settings);
add_filter( 'ninja_forms_render_default_value', 'my_change_nf_default_value', 10, 3 );
function my_change_nf_default_value( $default_value, $field_type, $field_settings ) {
if( 'textbox' == $field_type ){
$default_value = 'foo';
}
return $default_value;
}
@michelemarrionline
Copy link

michelemarrionline commented Apr 30, 2018

@degie.

how can i change a default value for a checkbox field?

if (is_user_logged_in()) {
	add_filter( 'ninja_forms_render_default_value', 'loadProfile' , 10 , 3);
	function loadProfile( $default_value, $field_type, $field_settings ) {
            //other code
	    if('allow_marketing' == $field_settings[ 'key' ]) {
	        $default_value = 'checked';
	    }

	  return $default_value;
	}
}

this is not working :(

@celestialhorizon
Copy link

Where to place this code? I can't find any documentation of it and its so confusing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment