Home Forums ACF PRO ACF_FORM() get return


ACF_FORM() get return

  • Hello,

    Sorry for my english 🙁

    I want to do a registration form with ACF Pro on my site.

    My Functions.php :

    add_filter('acf/save_post' , 'new_user_acf', 10, 1 );
    function new_user_acf(){
        $created = false;
        $data['login'] = $_POST["acf"]["field_5775904370cdf"]; 
        $data['email'] = $_POST["acf"]["field_5775908e70ce0"]; 
        $data['usr_password'] = $_POST["acf"]["field_577590b370ce1"]; 
        $data['confirm_password'] = $_POST["acf"]["field_577591f642e56"]; 
        $data['optin'] = $_POST["acf"]["field_577598009fbd3"];
        if($data['optin'] == "Oui"){
            $data['optin'] = 1;
            $data['optin'] = 0;
        if ($data['usr_password'] === $data['confirm_password']) {
            if (!username_exists($data['login'])) {
                if(email_exists($data['email']) === false){
                    $created = true;
                    $user_id = wp_create_user($data['login'], $data['usr_password'], $data['email']);
                } else {
                    $msg = __("Un compte utilisateur existe déjà avec cette adresse e-mail.", "wikoandco");
            } else {
                $msg = __('Ce nom d\'utilisateur est déjà utilisé', "wikoandco");
            $msg = __("Oups, votre mot de passe et sa confirmation sont différents", "wikoandco");
        if($created === true){
            $user = new WP_User($user_id);
            if(!wp_mail($data['email'], __("Bienvenue sur Wiko And Co'", "wikoandco"), __('Your password is:'. $usr_password, 'wikoandco'))){
                $msg .= "fail send";
                if(wp_mail("[email protected]", 'Nouvelle suscription e-mail', 'Un nouveau membre souhaite être ajouté à la newsletter :'.$email.' / '.$login)){
                    $msg = __("Inscription réussie mais votre inscription à la newsletter n'a pas pu être prise en compte. Vous pouvez souscrire à tout moment via votre espace membre.", "wikoandco");
                    $msg = __("Inscription réussie, bienvenue ! Vous pouvez dès à présent vous connecter", "wikoandco");
                $msg = __("Inscription réussie, bienvenue ! Vous pouvez dès à présent vous connecter", "wikoandco");
        return $msg; 

    I want get my $msg to show the message (error or success and if error : why)

    My registration page :

    <p id="register_zone">
       $options = array(
           'post_id' => 'new_post',
           'field_groups' => array( 141349 ),
           'form' => true,
           'submit_value' => __("Je m'inscris", "wikoandco"),
           'return' => '',
           'form_attributes' => array(
                 'id' => 'subscrib_form',
                 'name' => 'fm_acf',
                 'class' => '',
                 'action' => '',
                 'method' => 'post',
        acf_form($options); ?>

    If i do a die($msg), it’s good so my function is great. But how displayed my var $msg on my front ?

    Thanks a lot

  • Hi @triixx

    I’m afraid you can’t pass the message from the acf/save_post hook. What you can do is to create a list of error codes and then use the wp_redirect() function to add the parameters to the URL so it becomes something like this:

    Then you can check the error code and show it on the front end like this:

    if( $_GET['success'] == 'false' && $_GET['error'] = '1' ) {
        echo "Error message code 1";

    If you want, you can also use the cookie to pass the message. This page should give you more idea about it:

    I hope this helps 🙂

  • Hi James,

    Thanks 🙂

    It’s a great possibility but how i can put this data in my URL ? The redirection is done on the acf_form().


  • Hi @triixx

    Instead of return $msg;, I believe you can use the wp_redirect() function instead like this:

    // These are just for testing. You need to get the actual
    // value based on the registration
    $success = false;
    $error_code = '1'
    // if the registration failed
    if( !$success ){
        wp_redirect( '' . $error_code );


    I hope this helps 🙂

  • Hi,

    I finaly used acf_valide() before acf_save() and it’s good 🙂


Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.