• Resolved arturofez

    (@arturofez)


    Hello there!

    I’m trying to make a Pods form work for anonymous users, but it shows a JavaScript popup saying ‘Access denied, you are not connected’ when submitted.

    Initially, the form was not being displayed, so I enabled sessions in the Pods settings and set a ‘session save path’ via php.ini. Now the form is loaded, but it shows the JavaScript popup. In the browser console, I’m getting a 401 error with the ‘rest_not_logged_in’ code.

    Do I need to check something else? Thanks in advance

    Using Pods 2.9.15 with WordPress 6.2, form inserted via php snippet and function form().

    • This topic was modified 1 year, 9 months ago by arturofez.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Please share your exact PHP or try the [pods-form fields="x,y,z"] shortcode.

    Thread Starter arturofez

    (@arturofez)

    Okey, here is the code.

    $fields = [
    	'nombre',
    	'apellidos',
    	'nombre_organizacion',
    	'email_de_contacto',
    	'telefono',
    	'municipio',
    	'mensaje',
    	'entidad' => array( 'default' => $id, 'type' => 'hidden' ),
    ];
    
    echo $pods->form( $fields, 'Contactar' );

    The form is displayed, and I can submit it when I’m logged in, but it fails with anonymous users (users who are not logged in).

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @arturofez

    I tried to find this error in our code base but I couldn’t. Did you verify this issue is also happening with only Pods active on a default WordPress theme?

    https://docs.pods.io/faqs/plugin-theme-conflicts/

    Cheers, Jory

    Thread Starter arturofez

    (@arturofez)

    Okay, I finally found the problem.

    I tried to disable as many plugins as I could, but the problem persists. Then, I downloaded and installed WordPress locally, and the problem disappeared!

    After a lot of debugging, I realized that the function session_save_path() wasn’t always working correctly. It works fine if the function is called in a code snippet, but when it is called from the Pods API php file, it returns false!

    So I finally discovered that with my hosting provider, in order for changes in php.ini to take effect in all directories, you need to create a shortcut to php.ini in each directory. So, this would be a solution.

    I also tried setting the session.save_path directive in the .htaccess file, but it failed because PHP was running in “CGI mode.”

    Therefore, the simplest solution is to set the session save path in the wp_config.php file of WordPress, like this:

    @ini_set( 'session.save_path', 'route/to/session/save/path' );

    And it works every time! Thank you for the support, we can mark this as resolved.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Ah check! Thanks for sharing!

    Cheers, Jory

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pods form not working with anonymous users’ is closed to new replies.