Home › Forums › Front-end Issues › Existing front end form Events Manager
Hello,
I am a newvbie to ACF and I am trying to get ACF to work with events manager on the front end submission form but I can’t get it to work, I must be missing something very obvious but I might need a pointer in the right direction.
I have added groups and fields in ACF and placed them in the edit-event form template, all fields show and I can fill them out, but they do not get stored in the back end event post. They seem to get lost in a seperate event post with it’s own id in the database and not the actual event saved by events manager. When I fill out the fields in backend everything works and the fields are saved properly, so I do know it is working, it is just the front end form I can’t get to work.
I have got the add form before the get_header and this is the code for the form:
<?php acf_form(array(
'id' => 'event-form',
'post_id' => '$EM_Event->event_id',
'field_groups' => array(454,487,490,493,438,433.423,421),
'form' => false,
'return' => ''
));
?>
Can anybody give me push in the right direction to make it work?
Thank you
You need to set the id id' => 'event-form',
to the id of the event post being updated.
I know this is a couple of years old now, but I’m trying to do the same thing. @marieke_louise did you manage to locate the id of the event post, as per John’s answer? Where did you place the acf_form function? Could you share a sample of the code for adding the groups and fields into the edit-event form please? is this all working for you OK now or has this project moved on?
I’ve probably complicated things by using ACFE forms, that show up OK in the form, but I can’t save the contents at all. I’ve tried your code above, but can’t locate the form id in $_POST.
Thank you.
Old post yes, and I was incorrect in my original statement but since the OP did not reply I did not find that out. The ACF form argument that needs to be set is “post_id”.
I have not worked with the events plugin, so I do not know how to get the correct post ID to use in this argument.
Thanks John – The answer to getting the post_id is ‘$EM_Event->post_id’ within Events Manager templates or $events->post_id (usually) within most hooks.
I’ve gone for this approach to ‘manually’ add the fields.
One thing that I constantly look for but find hard to find, is how to ‘manually’ add ACF fields into a form. Input fields for add/edit on an external form.
My working trial code if anyone needs it:
function form_extras_post ($result, $event) {
if ( !is_null($_POST) ) {
$event_id = $event->post_id;
$field_name = 'organiser';
$field_value = $_POST['acf']['field_64a28d8f85a26'];
if ( ! empty( $field_value ) ) {
update_post_meta( $event_id, $field_name , $field_value );
}
}
}
add_filter( 'em_event_save', 'form_extras_post', 10, 2 );
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 );
The topic ‘Existing front end form Events Manager’ is closed to new replies.
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.