acf_form_front::submit_form
This function will submit form data
Method of the class: acf_form_front{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$acf_form_front = new acf_form_front(); $acf_form_front->submit_form( $form );
- $form(required)
- .
Changelog
| Since 5.5.10 | Introduced. |
acf_form_front::submit_form() acf form front::submit form code ACF 6.8.8
function submit_form( $form ) {
// filter
$form = apply_filters( 'acf/pre_submit_form', $form );
// vars
$post_id = acf_maybe_get( $form, 'post_id', 0 );
// add global for backwards compatibility
$GLOBALS['acf_form'] = $form;
// allow for custom save
$post_id = apply_filters( 'acf/pre_save_post', $post_id, $form );
// Restrict $_POST['acf'] to the field keys the form actually exposed, so the
// save path cannot accept values for fields the form did not render.
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in check_submit_form().
if ( isset( $_POST['acf'] ) && is_array( $_POST['acf'] ) ) {
$allowed_keys = $this->get_allowed_field_keys( $form );
$_POST['acf'] = array_intersect_key( $_POST['acf'], array_flip( $allowed_keys ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Sanitized downstream; save pipeline expects slashed input.
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
// save
acf_save_post( $post_id );
// restore form (potentially modified)
$form = $GLOBALS['acf_form'];
// action
do_action( 'acf/submit_form', $form, $post_id );
// vars
$return = acf_maybe_get( $form, 'return', '' );
// redirect
if ( $return ) {
// update %placeholders%
$return = str_replace( '%post_id%', $post_id, $return );
$return = str_replace( '%post_url%', get_permalink( $post_id ), $return );
// redirect
wp_redirect( $return ); //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- unsafe redirects allowed.
exit;
}
}