• Resolved Jess

    (@jeppner)


    Hi there,

    I’m trying to pass through an ACF from a field on the page where the form is submitted. In this case, we have franchises listed and we want to pass through the contact email for the franchise as a custom value.

    I’m using this 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;
    $value = get_field( $field_keys[1], $post_id );
    }
    return $value;
    }, 9999, 3 );

    And the ACF field’s name is: contact_email

    In Forminator, I have a hidden field with the custom value of acf_contact_email, however, every time I submit the form, it is showing as blank. I am using a custom post type called Franchises. Is this possibly why? If so, there is a way to make this work with custom post types?

    Thank you so much for any help! I love Forminator and use it on all my websites!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @jeppner

    I hope you’re well today!

    This is actually expected. What you do with the code is putting completely custom value into the “hidden” type field but since about 1.24 release hidden fields are additionally validated for security reasons and they can only contain values configured in field settings.

    So even though you do correctly set field value (and you can see it in page source code just fine), upon submission those values are compared with configured values and stripped off since they are different.

    Two simplest ways to solve that would be:

    1. You can replace hidden fields on the form with regular text (input) fields and then use “forminator_field_text_markup” filter to set value; then you can simply hide those fields with CSS

    2. Or you can try this:

    – set hidden field “Default value (optional)” option to “query var” and configure name of that query var (URL parameter) to some custom name
    – then use code to set $_POST['your_query_var_name'] upon page load, before the form is loaded.

    These are just suggested ways but if you need help with “ready to use” code, let us know and we should be able to provide it.

    Best regards,
    Adam

    Thread Starter Jess

    (@jeppner)

    Hi Adam, thank you so much for your response! I would greatly appreciate some ready-to-use code if you have the time. Unfortunately, I don’t think option 2 would work for us, but option 1 could! I can’t find the documentation for that filter myself. Thank you so much, I really appreciate it!

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jeppner,

    You can find an example usage for the forminator_field_text_markup filter as below:

    <?php
    add_filter( 'forminator_field_text_markup', function( $html, $field ) {
    		$field_id = 'text-1';
    
    		if ( ! empty( $field['element_id'] ) && $field_id ===  $field['element_id'] ) {
    			$html = "Your text here";
    		}
    		
    		return $html;
    	},
    	10,
    	2
    );

    You can pass the field to $html variable instead and check whether that works.

    Please do let us know how that goes.

    Best Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jeppner,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to open a new thread if you have new queries.

    Kind Regards
    Nithin

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Forminator with ACF Using Custom Post Type’ is closed to new replies.