FuturShoc Posted September 26, 2013 Posted September 26, 2013 I've been using this same code on my site's homepage form without a problem. However, I'm moving it to a stand-alone script called by the same form which is now on an interior page of the site. The script below is a plain PHP file that lives in a subfolder of the root directory. I'm getting no errors including the PW index file, per bootstrapping, but my api calls don't seem to be working... Can anyone help? <?php $email = $_POST['email']; $password = $_POST['password']; include("../../index.php"); if($email && $password) { if ($email == 'visitor') { $emailUser = $users->get("name=visitor"); } else { $email = $sanitizer->email($email); $emailUser = $users->get("email=$email"); } if($emailUser->id) { $user = $session->login($emailUser->name, $password); if($user) { $session->redirect('/catalog'); //echo 'logged in'; } else { echo "Login failed!"; } } else { echo "Unrecognized email address"; } } ?>
titanium Posted September 26, 2013 Posted September 26, 2013 Hi FuturShoc, try $emailUser = wire('users')->get("name=visitor"); $email = wire('sanitizer')->email($email); and so on... see http://processwire.com/api/include/ 1
FuturShoc Posted September 26, 2013 Author Posted September 26, 2013 Thank you, titanium. That seems to have done the trick for me, though this call gives me an internal server error: wire('sanitizer')->email($email); I had been referring to the API docs, but for some reason hadn't been using that syntax because it worked as-is on my site's home page... I wonder why it didn't require the wire() syntax...
teppo Posted September 27, 2013 Posted September 27, 2013 @FuturShoc: wire function (wire('api-var-name')) is needed outside PW template context where $sanitizer, $pages etc. API variables won't be defined. This is briefly explained in API docs too. Most commonly this affects functions, modules (where $this->pages etc. are also available) and bootstrapped scripts.There's probably something about that internal server error in your log files (PW and/or Apache) so you definitely should check those first. 2
FuturShoc Posted September 29, 2013 Author Posted September 29, 2013 Thanks for the clarification, teppo. That goes a long way toward my understanding the boundaries of bootstrap'ing PM. I knew it had to be some gap in my understanding, not an issue with PM itself.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now