Answers.Body: <p>Sounds like you need to <a href="http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions" rel="nofollow">allow anonymous access to your controller action</a>.</p>
  
  <p>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 <code>/login</code></p>
  
  <p>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.</p>
  
  <pre><code>// Will allow anonymous access to all actions within this controller
  protected $allowAnonymous = true;
  
  // Only allow access to specific actions
  protected $allowAnonymous = array('action addParticipant');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-16T07:35:22.557Z
Answers.LastActivityDate: 2015-09-16T07:35:22.557Z
Answers.UserDisplayName: Alec Ritson
Body: <p>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.</p>
  
  <p>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).</p>
  
  <p>Here is the form</p>
  
  <pre><code>&lt;form class="ui form" method="POST"&gt;
      &lt;div class="field"&gt;
          &lt;label&gt;Activité&lt;/label&gt;
               &lt;select name="activity" class="ui fluid dropdown"&gt;
                   &lt;option value="3"&gt;Third&lt;/option&gt;
                   &lt;option value="2"&gt;Second&lt;/option&gt;
                   &lt;option value="1"&gt;First&lt;/option&gt;
               &lt;/select&gt;
           &lt;/div&gt;
           &lt;div class="field"&gt;
               &lt;label&gt;Nom et prénom&lt;/label&gt;
               &lt;input name="nom" type="text"&gt;
           &lt;/div&gt;
  
           &lt;input type="hidden" name="action" value="eventEquipe/event/addParticipant"&gt;
           &lt;button class="positive ui fluid button" type="submit"&gt;Je viens !&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my controller's code
  public function actionAddParticipant() {</p>
  
  <pre><code>$this-&gt;requirePostRequest();
  
      $participant        = new EventEquipe_ParticipantRecord();
      $request            = craft()-&gt;request;
  
      $participant-&gt;nom       = $request-&gt;getPost('nom');
      $participant-&gt;activity  = $request-&gt;getPost('activity');
  
      craft()-&gt;eventEquipe_event-&gt;saveParticipant($participant);
      $this-&gt;redirect('/agenda');
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks for your help !</p>
  
Tags: <plugin-development><form><404>
Title: Form validation plugin result in 404
ThreadText: # Form validation plugin result in 404
  
  (Asked by: username_0 on 2015-09-16)
  
  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 !
  
  **Tags:** plugin-development, form, 404
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-16. Score: 1 | Accepted answer
  
  Sounds like you need to [allow anonymous access to your controller action](http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions).
  
  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');
  
  ```
  
  
  ---
  
  