• Resolved markovetski

    (@markovetski)


    Hi,

    I am trying to add a hidden field to the form in order to know which business opportunity the user is subscribed to.

    So I am using ACF text value “code” of each custom post and need it to be added to the submitted form.

    I have tried to play around with the solution you suggested on your support forum:
    https://premium.wpmudev.org/forums/topic/forminator-pro-autofill-add-custom-field/

    But with no luck. I couldn’t replace the “$company = get_user_meta( get_current_user_id(), ‘company’, true );” with the “$confirm = get_field(‘confirm’);” of the text field.

    I would really appreciate if you can guide me on that.

    Thanks,
    Eli.

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @markovetski ,

    Are you using the updated code from here https://premium.wpmudev.org/forums/topic/forminator-pro-autofill-add-custom-field/#post-3662767 that is for text input field?
    What does $confirm = get_field(‘confirm’); (when it’s used directly on the page) return on the page where you have your form?

    kind regards,
    Kasia

    Thread Starter markovetski

    (@markovetski)

    Hi Kasia,

    Thanks for your prompted reply ??

    I have tried both options (the hidden field and the input field).
    I have tried to implement the above code and try to adjust it to the $code=get_field(‘code’); but as you said it’s not the right way.

    So please let me start fresh ??
    I have a series of custom post and on each of them I have added a custom text field ‘code’.
    The ‘code’ is also visual to the users and functions as a catalog number of each post.
    Now, on each post, I add a Forminator contact form for the visitors to submit.
    Because I am using the same Forminator contact form on all of my customs posts I need that each submission will include the custom text field “code” so I will know to which custom post the visitor has applied.

    I have no importance if the code will be visible or not so both ways are workable for me.

    Hope that it is more clear now.

    Thanks again for all your help and support,
    Eli.

    Thread Starter markovetski

    (@markovetski)

    Hi Kasia,

    In case you have missed my reply I am promoting it again.

    Thanks,
    Eli

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @markovetski ,

    I’m sorry for the late response. I have tested code for the Forminator with ACF and it works correctly.
    This is code I’m using for the mu-plugin:

    <?php
    
    add_filter(
    
    'forminator_field_markup',
    
    function( $html ) {
    
    if ( is_user_logged_in() ) {
    
    $company = get_field( 'myfield' );
    
    if ( ! empty( $company ) ) {
    
    $html = str_replace( '%my_value_1%', $company, $html );
    
    }
    
    } else {
    
    $html = str_replace( '%my_value_1%', '', $html );
    
    }
    
    return $html;
    
    },
    
    99
    
    );

    my custom field is myfield.
    Please note that this code has condtion for the logged-in user:
    if ( is_user_logged_in() ) {

    This exported simple form with this field:
    {"type":"form","data":{"fields":[{"id":"text-1","element_id":"text-1","form_id":"wrapper-1763-5888","type":"text","options":[],"cols":12,"conditions":[],"wrapper_id":"wrapper-1763-5888","input_type":"line","limit_type":"characters","field_label":"Text","placeholder":"E.g. text placeholder","default":"%my_value_1%"}],"settings":{"formName":"afcfields","pagination-header":"nav","version":"1.10.2","form-border-style":"none","form-padding":"","form-border":"","fields-style":"open","validation":"on_submit","form-style":"default","enable-ajax":"true","autoclose":"true","submission-indicator":"show","indicator-label":"Submitting...","paginationData":{"pagination-header-design":"show","pagination-header":"nav"},"submission-behaviour":"behaviour-thankyou","thankyou-message":"Thank you for contacting us, we will be in touch shortly.","submitData":{"custom-submit-text":"Send Message","custom-invalid-form-message":"Error: Your form is not valid, please fix the errors!"},"validation-inline":"1","form-expire":"no_expire","form-padding-top":"0","form-padding-right":"0","form-padding-bottom":"0","form-padding-left":"0","form-border-width":"0","form-border-radius":"0","cform-label-font-family":"Roboto","cform-label-custom-family":"","cform-label-font-size":"12","cform-label-font-weight":"bold","cform-title-font-family":"Roboto","cform-title-custom-family":"","cform-title-font-size":"45","cform-title-font-weight":"normal","cform-title-text-align":"left","cform-subtitle-font-family":"Roboto","cform-subtitle-custom-font":"","cform-subtitle-font-size":"18","cform-subtitle-font-weight":"normal","cform-subtitle-text-align":"left","cform-input-font-family":"Roboto","cform-input-custom-font":"","cform-input-font-size":"16","cform-input-font-weight":"normal","cform-radio-font-family":"Roboto","cform-radio-custom-font":"","cform-radio-font-size":"14","cform-radio-font-weight":"normal","cform-select-font-family":"Roboto","cform-select-custom-family":"","cform-select-font-size":"16","cform-select-font-weight":"normal","cform-multiselect-font-family":"Roboto","cform-multiselect-custom-font":"","cform-multiselect-font-size":"16","cform-multiselect-font-weight":"normal","cform-dropdown-font-family":"Roboto","cform-dropdown-custom-font":"","cform-dropdown-font-size":"16","cform-dropdown-font-weight":"normal","cform-calendar-font-family":"Roboto","cform-calendar-custom-font":"","cform-calendar-font-size":"13","cform-calendar-font-weight":"normal","cform-button-font-family":"Roboto","cform-button-custom-font":"","cform-button-font-size":"14","cform-button-font-weight":"500","cform-timeline-font-family":"Roboto","cform-timeline-custom-font":"","cform-timeline-font-size":"12","cform-timeline-font-weight":"normal","cform-pagination-font-family":"","cform-pagination-custom-font":"","cform-pagination-font-size":"16","cform-pagination-font-weight":"normal","payment_require_ssl":"","submission-file":"delete"},"client_id":null,"notifications":[{"slug":"notification-1234-4567","label":"Admin Email","email-recipients":"default","recipients":"[email protected]","email-subject":"New Form Entry #{submission_id} for {form_name}","email-editor":"You have a new website form submission: <br/> {all_fields} <br/>---<br/> This message was sent from {site_url}."}]},"status":"publish","version":"1.10.2"}

    This is how the field looks like on front end:

    inside there is the value from the custom field that was added to the post.

    kind regards,
    Kasia

    Thread Starter markovetski

    (@markovetski)

    Thanks Kasia ????????????,

    All good now ??

    Solved.

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @markovetski ,

    You might want to remove my email from the form you have imported since I’m getting all the tests from your site ??

    kind regards,
    Kasia

    Thread Starter markovetski

    (@markovetski)

    OOOOOOOOOOOOOOOOOOOOOOPPPS ??

    Sure. Sorry about that.

    Done!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using Hidden field ACF (Advanced custom field) text value’ is closed to new replies.