<p>You may be able to use the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button" rel="nofollow noreferrer">browser-native <code>&lt;button type=&quot;submit&quot;&gt;</code> feature</a>!</p>
<p>Check this out:</p>
<pre><code>&lt;form method=&quot;POST&quot;&gt;
  {{ csrfInput() }}
  {{ actionInput('commerce/carts/update-cart') }}

  {# ...your existing form controls... #}

  &lt;button
    type=&quot;submit&quot;
    name=&quot;redirect&quot;
    value=&quot;{{ 'update/path/target' | hash  }}&quot;&gt;Update Quantities&lt;/button&gt;

  &lt;button
    type=&quot;submit&quot;
    name=&quot;redirect&quot;
    value=&quot;{{ 'checkout/path/target' | hash  }}&quot;&gt;Checkout&lt;/button&gt;
&lt;/form&gt;
</code></pre>
<p>The only peculiar thing to note here is the direct use of Craft's <a href="https://craftcms.com/docs/3.x/dev/filters.html#hash" rel="nofollow noreferrer"><code>hash</code> filter</a>—ultimately the same functionality that <code>redirectInput()</code> helper provides, as a means to prevent tampering with the values and exposing your app to remote code execution vulnerabilities!</p>

CC BY-SA 4.0
2022-03-17T18:34:14.857Z
Thanks! This works like a charm. For anyone else wondering the `hash` filter is necessary. If you don't do it you'll get `HTTP 400 – Bad Request`.
Yawner
CC BY-SA 4.0
2022-03-17T17:38:52.847Z
2022-03-18T04:47:56.563Z
2022-03-18T04:47:56.563Z
August Miller
<p>I'm building a basic cart page in Craft 3.7.37 with Commerce 3.4.12. The <code>/store/cart</code> page has a <code>&lt;form&gt;</code> with the line items in the cart next to an <code>&lt;input /&gt;</code> to change quantity and one to remove the line item. I also have an &quot;Update Cart&quot; button that updates quantities from the form (redirecting back to <code>/store/cart</code>) and a &quot;Checkout&quot; button that currently just submits the form. I've added a <a href="https://craftcms.com/docs/3.x/dev/functions.html#redirectinput" rel="nofollow noreferrer"><code>redirectInput</code></a> function to the form to redirect back to <code>/store/cart</code> on submit, which works for the &quot;Update Cart&quot; and &quot;Remove&quot; buttons.</p>
<p>How do I make the &quot;Checkout&quot; button redirect to <code>/store/checkout/contact</code> and update cart quantities when the user clicks it?</p>
<p>I know this is possible in PHP server side but I'm not great at PHP. I'm hoping there's a a way to use Craft's built-in functions. I want to avoid using jQuery ajax and Javascript form processing if possible (as in this <a href="https://craftcms.stackexchange.com/questions/15627/craft-commerce-add-to-cart-and-then-redirect-to-product-page">question</a>). I also want to ensure <a href="https://craftcms.stackexchange.com/questions/28794/craft-3-registration-form-success-redirect">urls are hashed</a>.</p>
<p>Here's the relevant template code:</p>
<pre><code>&lt;form method=&quot;POST&quot; data-cart&gt;
&lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;commerce/cart/update-cart&quot; /&gt;
{{ redirectInput('/store/cart') }}
{{ csrfInput() }}
&lt;input type=&quot;hidden&quot; name=&quot;gatewayId&quot; value=&quot;{{ gatewayId }}&quot; /&gt;
{% set item = item | default(false) %}
{% set maxQty = maxQty | default('') %}
{% set summary = summary | default(false) %}
{% if item %}
{% set sum = item.price * item.qty %}
{% if summary %}
&lt;p class=&quot;cart-items__item__summary&quot;&gt;
    {{ item.qty }} &amp;times; {{ item.price | currency }} = {{ sum | currency }}
&lt;/p&gt;
{% else %}
&lt;div class=&quot;cart-items__item__fields&quot;&gt;
    &lt;label class=&quot;cart-items__item__qty&quot;&gt;
        {{ item.price | currency }}
        &amp;times;
        &lt;input max=&quot;{{ maxQty }}&quot; min=&quot;0&quot; name=&quot;lineItems[{{ item.id }}][qty]&quot; placeholder=&quot;qty&quot; step=&quot;1&quot; type=&quot;number&quot; value=&quot;{{ item.qty }}&quot; /&gt;
        =
        {{ sum | currency }}
    &lt;/label&gt;
    &lt;label class=&quot;cart-items__item__remove&quot;&gt;
        &lt;input name=&quot;lineItems[{{ item.id }}][remove]&quot; type=&quot;submit&quot; value=&quot;{{ item.qty }}&quot; /&gt;
        Remove
    &lt;/label&gt;
&lt;/div&gt;
{% endif %}
{% endif %}
&lt;div class=&quot;actions&quot;&gt;
    &lt;a href=&quot;/store&quot; class=&quot;button actions__action&quot;&gt;&amp;larr; Back to Store&lt;/a&gt;
    &lt;button type=&quot;submit&quot; class=&quot;button actions__action&quot;&gt;Update Cart&lt;/button&gt;
    &lt;button type=&quot;submit&quot; class=&quot;button actions__action&quot;&gt;Checkout &amp;rarr;&lt;/button&gt;
&lt;/div&gt;
</code></pre>

<p>and a screenshot of the front-end to help clarify:
<a href="https://i.sstatic.net/84vz7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/84vz7.png" alt="enter image description here" /></a></p>

<craft3><templating><php><plugin-craftcommerce3>
Craft Commerce: Multiple redirect submit buttons from cart form (checkout/update cart) without ajax
# Craft Commerce: Multiple redirect submit buttons from cart form (checkout/update cart) without ajax

(Asked by: username_0 on 2022-03-17)

I'm building a basic cart page in Craft 3.7.37 with Commerce 3.4.12. The /store/cart page has a  with the line items in the cart next to an  to change quantity and one to remove the line item. I also have an "Update Cart" button that updates quantities from the form (redirecting back to /store/cart) and a "Checkout" button that currently just submits the form. I've added a redirectInput function to the form to redirect back to /store/cart on submit, which works for the "Update Cart" and "Remove" buttons.
How do I make the "Checkout" button redirect to /store/checkout/contact and update cart quantities when the user clicks it?
I know this is possible in PHP server side but I'm not great at PHP. I'm hoping there's a a way to use Craft's built-in functions. I want to avoid using jQuery ajax and Javascript form processing if possible (as in this question). I also want to ensure urls are hashed.
Here's the relevant template code:


{{ redirectInput('/store/cart') }}
{{ csrfInput() }}

{% set item = item | default(false) %}
{% set maxQty = maxQty | default('') %}
{% set summary = summary | default(false) %}
{% if item %}
{% set sum = item.price * item.qty %}
{% if summary %}

    {{ item.qty }} × {{ item.price | currency }} = {{ sum | currency }}

{% else %}

    
        {{ item.price | currency }}
        ×
        
        =
        {{ sum | currency }}
    
    
        
        Remove
    

{% endif %}
{% endif %}

    ← Back to Store
    Update Cart
    Checkout →


and a screenshot of the front-end to help clarify:

**Tags:** craft3, templating, php, plugin-craftcommerce3


---

## 1 answers

### Answer by username_1 on 2022-03-17. Score: 3 | Accepted answer

You may be able to use the browser-native  feature!
Check this out:

  {{ csrfInput() }}
  {{ actionInput('commerce/carts/update-cart') }}

  {# ...your existing form controls... #}

  Update Quantities

  Checkout


The only peculiar thing to note here is the direct use of Craft's hash filter—ultimately the same functionality that redirectInput() helper provides, as a means to prevent tampering with the values and exposing your app to remote code execution vulnerabilities!

> **Comments:**
> **username_0**: Thanks! This works like a charm. For anyone else wondering the `hash` filter is necessary. If you don't do it you'll get `HTTP 400 – Bad Request`.  

---

