Support

Account

Home Forums General Issues Stop form submit if user not logged in

Solving

Stop form submit if user not logged in

  • Hello, I’ve used acf_form() to create a front end form however I’d only like the form to be saved on submit if the user is logged in. I’ve tried using unset($_POST[‘acf’]) and acf/pre_save_post but the post stills saves without values. Is there a way to stop the save process if the user is not logged in?

  • Instead of trying to prevent the form from being submitted you should not show the form if the user is not logged in.

    
    if (is_user_logged_in()) {
      acf_form();
    } else {
      ?><p>you must be logged in to view the form</p><?php 
    }
    
  • Thanks for your response John. I’d like to keep the form visible to all so people know what is required without logging in. Is it possible to prevent in the back end?

    As an aside, I’m trying to use the plugin Login with Ajax to activate the form submit button once the user logs in (without page refresh).

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

The topic ‘Stop form submit if user not logged in’ is closed to new replies.