Answers.Body: <p>Just like a lot of things in Craft or in computer science in general, there's multiple ways to do things.</p>
  <p>The <code>actionInput</code> function is just a shortcut for outputting a hidden input:</p>
  <pre><code>&lt;input type=&quot;hidden&quot; name=&quot;whatever&quot; value=&quot;whatever&quot;&gt;
  </code></pre>
  <p>...much like <code>{{ entry.title }}</code> in Twig is really a shortcut in PHP for something like <code>&lt;?php echo twig_escape_filter(...) ?&gt;</code>.</p>
  <p>However, the 2 snippets you posted are not necessarily equivalent.</p>
  <p>When you put the &quot;action&quot; attribute on a form:</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;whatever&quot;&gt;
  </code></pre>
  <p>... a web browser is actually sending a POST request to that location, versus when you leave it off:</p>
  <pre><code>&lt;form method=&quot;post&quot;&gt;
  </code></pre>
  <p>... a browser will POST to the current page.</p>
  <p>The difference seems subtle but say your form has errors, you probably don't want to be POSTing to your controller &quot;directly&quot;, you want to reload the same page. (And you don't typically don't want someone bookmarking your controller action.)</p>
  <p>The older Craft 2.X documentation has a great little <a href="https://craftcms.com/docs/2.x/plugins/controllers.html" rel="nofollow noreferrer">bit</a> about this:</p>
  <blockquote>
  <p>When you leave your form’s ‘action’ attribute blank, browsers will default to the current request’s URL. Which is great in the event that your controller needs to reload the previous page without a redirect. A common example of this is when the user’s input didn’t validate, and you want to pass the errors back to your template (ideally tucked away within a model).</p>
  </blockquote>
  <p>Craft/Yii handles the nitty-gritty routing behind the scenes.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-19T18:08:32.983Z
Answers.Text: Gotcha thanks. The route params are the big difference from what I can tell, which you can sorta work around with flashes and session in your own controllers. This is mostly just coming up because we are playing with adding https://turbo.hotwire.dev/ and it doesn't play nicely with the action input.
Answers.UserDisplayName: Trevor Davis
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-18T21:06:51.007Z
Answers.LastActivityDate: 2021-05-18T21:06:51.007Z
Answers.UserDisplayName: RitterKnight
Body: <p>What is the value in using a hidden <a href="https://craftcms.com/docs/3.x/dev/functions.html#actioninput" rel="nofollow noreferrer">actionInput</a> vs an action attribute on a form?</p>
  <pre><code>&lt;form method=&quot;post&quot;&gt;
      {{ actionInput('path/to/controller-action') }}
  &lt;/form&gt;
  </code></pre>
  <p>vs</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;/actions/path/to/controller-action&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I understand you get the actionTrigger automatically added, but you could use the <a href="https://craftcms.com/docs/3.x/dev/functions.html#actionurl" rel="nofollow noreferrer">actionUrl</a> function to generate that as well.</p>
  
Tags: <form><controller><action>
Title: What value does actionInput provide?
ThreadText: # What value does actionInput provide?
  
  (Asked by: username_0 on 2021-05-17)
  
  What is the value in using a hidden [actionInput](https://craftcms.com/docs/3.x/dev/functions.html#actioninput) vs an action attribute on a form?
  
  ```
  <form method="post">
      {{ actionInput('path/to/controller-action') }}
  </form>
  
  ```
  
  vs
  
  ```
  <form method="post" action="/actions/path/to/controller-action">
  </form>
  
  ```
  
  I understand you get the actionTrigger automatically added, but you could use the [actionUrl](https://craftcms.com/docs/3.x/dev/functions.html#actionurl) function to generate that as well.
  
  **Tags:** form, controller, action
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-05-18. Score: 2 | Accepted answer
  
  Just like a lot of things in Craft or in computer science in general, there's multiple ways to do things.
  
  The `actionInput` function is just a shortcut for outputting a hidden input:
  
  ```
  <input type="hidden" name="whatever" value="whatever">
  
  ```
  
  ...much like `{{ entry.title }}` in Twig is really a shortcut in PHP for something like `<?php echo twig_escape_filter(...) ?>`.
  
  However, the 2 snippets you posted are not necessarily equivalent.
  
  When you put the "action" attribute on a form:
  
  ```
  <form method="post" action="whatever">
  
  ```
  
  ... a web browser is actually sending a POST request to that location, versus when you leave it off:
  
  ```
  <form method="post">
  
  ```
  
  ... a browser will POST to the current page.
  
  The difference seems subtle but say your form has errors, you probably don't want to be POSTing to your controller "directly", you want to reload the same page. (And you don't typically don't want someone bookmarking your controller action.)
  
  The older Craft 2.X documentation has a great little [bit](https://craftcms.com/docs/2.x/plugins/controllers.html) about this:
  
  > When you leave your form’s ‘action’ attribute blank, browsers will default to the current request’s URL. Which is great in the event that your controller needs to reload the previous page without a redirect. A common example of this is when the user’s input didn’t validate, and you want to pass the errors back to your template (ideally tucked away within a model).
  
  Craft/Yii handles the nitty-gritty routing behind the scenes.
  
  > **Comments:**
  > **username_0**: Gotcha thanks. The route params are the big difference from what I can tell, which you can sorta work around with flashes and session in your own controllers. This is mostly just coming up because we are playing with adding https://turbo.hotwire.dev/ and it doesn't play nicely with the action input.  
  
  ---
  
  