Skip to content

Instantly share code, notes, and snippets.

@joelstransky
Created August 17, 2015 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelstransky/c87cc56923abe15b144b to your computer and use it in GitHub Desktop.
Save joelstransky/c87cc56923abe15b144b to your computer and use it in GitHub Desktop.
Bypass Advanced Custom Fields acf_form() create/update post functionality
function acf_contact_form_head() {
// verify nonce
if( acf_verify_nonce('acf_form') ) {
// validate data
if( acf_validate_save_post(true) ) {
// form
$GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form');
$GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true);
// validate
if( empty($GLOBALS['acf_form']) ) {
return;
}
$from_field = "field_55ccea67a2a49";
$email_field = "field_55cceafca2a4a";
$subject_field = "field_55cceb5aa2a4b";
$message_field = "field_55ccec4ca2a4c";
$from = $_POST['acf'][$from_field];
$email = $_POST['acf'][$email_field];
$acf_subject = get_field_object($subject_field);
$subject = $acf_subject['choices'][$_POST['acf'][$subject_field]];
$message = $_POST['acf'][$message_field];
send_mail($from, $email, $subject, $message);
// vars
//$return = acf_maybe_get( $GLOBALS['acf_form'], 'return', '' );
// redirect
if( $return ) {
// update %placeholders%
$return = str_replace('%post_url%', get_permalink($post_id), $return);
// redirect
wp_redirect( $return );
exit;
}
}
// if
}
// if
// load acf scripts
acf_enqueue_scripts();
}
@joelstransky
Copy link
Author

Just add this to your theme's functions.php and insert acf_contact_form_head() before get_header() instead of acf_form_head()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment