• Resolved fdcommunication

    (@fdcommunication)


    Hello,

    https://www.ads-software.com/support/topic/hidden-field-getting-data-from-acf/

    I see this thread and I want exactly the same thing. But the code is not working :

    <?php
    add_filter( 'forminator_field_hidden_field_value', function( $value, $saved_value, $field ){
    	if( ! empty( $field['default_value'] ) && 'custom_value' === $field['default_value'] && strpos( $value, 'acf_' ) !== false ){
    		$field_keys = explode('acf_', $value );
    		$post_id = false;//default is current post/page
    		$value = get_field( $field_keys[1], $post_id );
    	}
    	return $value;
    }, 10, 3 );

    I add this code in the plugin Snippet and select custom value in hidden field, with my acf value : acf_reference_du_circuit.

    What am I missing ?

    Thank you a lot for your help !

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @fdcommunication

    I hope you are doing well today.

    I pinged our SLS Team to review your query and double-check if this snippet is still valid. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi again @fdcommunication

    We have track main issue which is your “acf_reference_du_circuit”.

    The custom field name should be reference_du_circuit . If you’re keeping the custom field name acf_reference_du_circuit then it won’t work.

    The snippet is such that it will exclude?acf_and then will use the rest of the string in?get_field?function.

    In short the hidden field it should be?acf_reference_du_circuit?and custom field name should be?reference_du_circuit

    Kind Regards,
    Kris

    Thread Starter fdcommunication

    (@fdcommunication)

    Hello,

    Thank you for your answer !

    My ACF field is reference_du_circuit. So I put this code in Snippets plugin:

    add_filter( 'forminator_field_hidden_field_value', function( $value, $saved_value, $field ){
    	if( ! empty( $field['default_value'] ) && 'custom_value' === $field['default_value'] && strpos( $value, 'reference_du_circuit' ) !== false ){
    		$field_keys = explode('reference_du_circuit', $value );
    		$post_id = false;//default is current post/page
    		$value = get_field( $field_keys[1], $post_id );
    	}
    	return $value;
    }, 10, 3 );

    Then I add a hidden field {hidden-2} to my form. Select custom value and write reference_du_circuit in custom value field.

    Unfortunately it doesn’t work :(.

    In my submission form it is only written “Hidden” without the content of my acf field.

    What can I do ?

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @fdcommunication

    You should use the original code:

    add_filter( 'forminator_field_hidden_field_value', function( $value, $saved_value, $field ){
    	if( ! empty( $field['default_value'] ) && 'custom_value' === $field['default_value'] && strpos( $value, 'acf_' ) !== false ){
    		$field_keys = explode('acf_', $value );
    		$post_id = false;//default is current post/page
    		$value = get_field( $field_keys[1], $post_id );
    	}
    	return $value;
    }, 10, 3 );

    Only change is that in the hidden field’s custom value you should write?acf_reference_du_circuit?instead of?reference_du_circuit

    Kind Regards,
    Kris

    Thread Starter fdcommunication

    (@fdcommunication)

    It works ! Thank you very much.

    And thank you for being so reactive !

    Have a good day.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hidden field getting data from ACF’ is closed to new replies.