Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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