1

I'm new to craft development, and I'm on the verge of success in the creation of my plugin, but I have a strange problem.

It's supposed to save a record based on user input data. The problem is that it works on my computer, but not on my mobile phone (-> result in 404).

Here is the form

<form class="ui form" method="POST">
    <div class="field">
        <label>Activité</label>
             <select name="activity" class="ui fluid dropdown">
                 <option value="3">Third</option>
                 <option value="2">Second</option>
                 <option value="1">First</option>
             </select>
         </div>
         <div class="field">
             <label>Nom et prénom</label>
             <input name="nom" type="text">
         </div>

         <input type="hidden" name="action" value="eventEquipe/event/addParticipant">
         <button class="positive ui fluid button" type="submit">Je viens !</button>
</form>

Here is my controller's code public function actionAddParticipant() {

$this->requirePostRequest();

    $participant        = new EventEquipe_ParticipantRecord();
    $request            = craft()->request;

    $participant->nom       = $request->getPost('nom');
    $participant->activity  = $request->getPost('activity');

    craft()->eventEquipe_event->saveParticipant($participant);
    $this->redirect('/agenda');
}

The problem is that sometimes, this redirects me to /login (I dont know why, I have no /login route) and thus result in a 404.

Thanks for your help !

1 Answer 1

1

Sounds like you need to allow anonymous access to your controller action.

I guess it works on your computer because you are logged in and thus have a valid session, but then when you try on mobile, you haven't got a valid session, your controller isn't set up to allow logged out users to post to it and therefore you get redirected to /login

To allow non logged in users access to this action, its simple. Add either one of these just at the top within your controller class.

// Will allow anonymous access to all actions within this controller
protected $allowAnonymous = true;

// Only allow access to specific actions
protected $allowAnonymous = array('action addParticipant');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.