Global fields / elements
Need the same field or element on existing forms? The global field method might be helpful in these scenario's. To add a field to all your existing forms by altering the form via WordPress hooks.
function f4d_add_hidden_field($value, $form_id, $meta_key, $single){
$meta_needed = '_super_elements';
if(isset($meta_key) && $meta_needed===$meta_key){
// (optional condition: skip forms with the following ID) if($form_id===123 || $form_id===124) return;
// (optional condition: only alter forms with the following ID) if($form_id!==123 && $form_id!==124) return;
remove_filter('get_post_metadata', 'f4d_add_hidden_field', 10);
$value = get_post_meta($form_id, $meta_needed, true);
$json = '{"tag":"hidden","group":"form_elements","data":{"name":"page_url","email":"Hidden:","value":"{post_permalink}"}}';
$value[] = json_decode($json, true);
return array($value);
}
// Return original if the check does not pass
return $value;
}
add_filter('get_post_metadata', 'f4d_add_hidden_field', 10, 4);Last updated