Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Deaner666
Created May 27, 2015 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deaner666/5dbd39c28af218aa6845 to your computer and use it in GitHub Desktop.
Save Deaner666/5dbd39c28af218aa6845 to your computer and use it in GitHub Desktop.
Pre-populate Ninja Forms fields from URL parameters
<?php
add_filter( 'ninja_forms_field', 'wpm_handle_http_query_string' );
function wpm_handle_http_query_string( $data ) {
// A list field with label "Tier"
if($data['label']=='Tier' && get_query_var('tier')) {
foreach ($data['list']['options'] as $key => $value) {
if($value['value'] == get_query_var('tier')) {
$data['list']['options'][$key]['selected'] = 1;
}
}
}
// A textbox field with label "First name"
if($data['label']=='First name' && get_query_var('first-name')) {
$data['default_value'] = get_query_var('first-name');
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment