Home › Forums › Front-end Issues › Existing front end form Events Manager › Reply To: Existing front end form Events Manager
Just an update on the above with the now working version. This filter is in the root file of my plugin or could sit in functions.php of a theme.
I noticed in the database that items were being stored with their name on the backend and not their ACF key (as in the previous version).
I’m using this with ACF Extended forms – In the setup for these. In General there is a ‘post action’ set to update, with save set to current post, save ACF fields are all OFF. Load is set to ‘Yes’ with Load ACF fields set to all ON. In Settings the Form element and Submit button are OFF. Everything else is at their default settings.
This also appears to work for multiple acfe forms in the same template. (Events Manager: event-editor.php)
function my_form_extras_post ($result, $event) {
if ( (!empty($_POST)) && (!is_admin()) ) { //check for post variables and ignore if on the admin pages.
//Will iterate over each ACF field held in $_POST and save it.
foreach ( $_POST['acf'] as $ec_field => $ec_field_value) {
$event_id = $event->post_id; //post_id of the event ('500')
$field_key = $ec_field; //The ACF field Key ('field_al2354sdfjdf')
$field_details = get_field_object($field_key); //The ACF field detail - array
$field_name = $field_details['name']; //The ACF name for the field (company_name)
$field_value = $ec_field_value; //The value in the field as typed in on the interface ('Truck Mart')
if ( !empty( $field_value ) ) { //Do nothing if the value field is empty
update_post_meta( $event_id, $field_name , $field_value ); //Creates or updates the meta field holding the value
update_post_meta( $event_id, "_".$field_name, $field_key ); //Creates or updates the meta field holding the ACF reference (note the '_' underscore in front of the name)
}
}
}
}
add_filter( 'em_event_save', 'my_form_extras_post', 10, 2 );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.