Custom Fields
Re-Envisioned
Support MB Frontend Submission Only showing certain custom fields on the frontend submission?

  • Creator
    Topic
  • #30104
    Resolved John
    Participant

    Sorry, this seems so obvious that I must be overlooking it in the documentation (and I've searched the forum too) but how do I set a frontend submission form to ignore some custom fields?

    Specifically in this case, I'm saving longitude and latitude for an address from Google Maps and I don't want that (or most of the other address data I am saving) showing on the frontend form.

    Thanks
    John

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #30138
    Long Nguyen
    Moderator

    Hi John,

    If you want to show the fields on the backend only, when registering the meta box and custom fields, please check if it's the admin area. For example

    function register_meta_boxes( $meta_boxes ) {
        if( is_admin() ) {
            $meta_boxes[] = [
                ...
            ];
        }    
        return $meta_boxes;
    }
    
    #30147
    John
    Participant

    Thanks Long. I'm using the builder at the moment but could get the php code and edit it. So if I do that and put the fields I don't want the users to see on the frontend in the is_admin block, then they will only be visible in the backend but not the frontend? What happens then to the Google Maps integration where it automatically stores the longitude and latitude? If the fields aren't on the front end will they ever be saved? I appreciate I could hide with CSS but that's not ideal.

    On a related note, is there a guide to using Elementor (Pro or otherwise) to generate frontend submission forms?

    Thanks

    #30168
    Long Nguyen
    Moderator

    Hi John,

    Yes, the condition code helps you to show a/some meta boxes on the backend only and you (or someone who can access to admin area) can add the data to save them as well. You need to have a basic knowledge of coding and using the code to do more advanced cases.

    Frontend submission form is generated automatically if you use the Builder, screenshot https://share.getcloudapp.com/6quY0AD5

    Or created manually https://docs.metabox.io/extensions/mb-frontend-submission/

    Then you can add the shortcode to the textarea/shortcode widget of the Builder.

    #30220
    John
    Participant

    Thanks Long. I'm an advanced developer so coding is fine. Just trying to get to grips with how your system works.

    In terms of my question re lon/lat for google maps, in this particular scenario, would they not be saved? In fact, let's put it another way.

    If I had a submission form that had a google map on it, and an autocomplete address field, and I wanted it to save all the individual fields (postcode, country, etc) separately, at the moment I've got all those fields on the form.

    If I were to hide them on the frontend using the admin condition, I'm going to guess they wouldn't be saved as they won't be in the form?

    If that's the case, would I need to write a hook after the submission to get the address that is saved in the publicly visible fields, feed that to the Google Maps API, and get all the separate fields again?

    Thanks
    John

    #30233
    Long Nguyen
    Moderator

    Hi John,

    Yes, if the meta box is not loaded on the frontend, the post submitted wouldn't save the field value. There is some form hooks that let you update the field value after submitting posts, please find it here https://docs.metabox.io/extensions/mb-frontend-submission/#form-actions

    #30234
    John
    Participant

    Thanks Long!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.