Hello.
I am trying to hide fields in a form unless the gf_token is present.
I have this start:
/**
* Check to see if the second user is viewing the form (based on whether the Gravity Forms token is present).
*
* @return boolean
*/
function prefix_does_token_exist() {
return (bool) filter_input( INPUT_GET, 'gf_token', FILTER_SANITIZE_STRING );
}
I know how to get the field id, etc., but would this be appropriate for the render page just like shown in the following example?
https://community.gravityforms.com/t/how-to-change-hidden-field-to-visible-with-php-code/16239/2
I came up with this:
add_filter( 'gform_pre_render', 'conditionally_show_field' );
function conditionally_show_field( $form ) {
// Replace 10 with your form ID
if ( $form['id'] != 1 ) {
return $form;
}
// Replace 2 with your field ID
$field_id = 2;
// Check if the current token exists
if ( prefix_does_token_exist() ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->id == $field_id ) {
$field->visibility = 'visible';
}
}
}
return $form;
}
I would assume this would work. Does this look right? I need to make the form ID selection an array or set of fields, ie more than one. Any input is welcome.
-d