Changing the value of an option on submission.

Support MB Frontend Submission Changing the value of an option on submission.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #47171
    Anchen le RouxAnchen le Roux
    Participant

    I have a front end form on this page: https://kambriaevans.com/intensive-directory-submissions/
    For the option fields Modalities Used and Populations Served I want to show the option Other but I want it to save as Other - See below for more info.
    On submit it creates a new post type called 'intensive-directory'

    I don't have issues changing the data on text fields, but the array is giving some issues.

    Here's what I have atm, but not working. I assume I'm not getting the array correctly (Only for Modalities Used field)

    function modify_modalities_used_field($data, $postarr) {
        // Check the post type to ensure it's for 'intensive-directory'
        if ($data['post_type'] === 'intensive-directory') {
            // Check if the custom field 'modalities_used' exists in the submitted data
            if (isset($postarr['meta_input']['modalities_used']) && $postarr['meta_input']['modalities_used'] === 'other') {
                // Change the value to 'Other - See below for more info'
                $postarr['meta_input']['modalities_used'] = 'Other - See below for more info';
            }
        }
        return $data;
    }
    add_filter('wp_insert_post_data', 'modify_modalities_used_field', 10, 2);
    #47184
    PeterPeter
    Moderator

    Hello,

    It requires login to view the frontend form on the page so I cannot check the field type on your site https://kambriaevans.com/intensive-directory-submissions/

    If it is a select field, you need to assign the field to its option value which is registered when you create the field, such as other, green, blue ... and not the option label.

    Please follow the documentation https://docs.metabox.io/fields/select/

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