Home  >  Q&A  >  body text

When the form is submitted, the action URL fails to jump correctly.

<p>When I submit the form, instead of taking me to the correct URL, it just stays on the same URL and adds the parameters to it. Like this: /todo?message=themessage instead of /todo/add</p> <pre class="brush:php;toolbar:false;"><form> <div class="form-group" action="/todo/add" method="POST"> <label for="message">Add new to-do message</label> <input type="text" class="form-control" name="message" id="message"> <button type="submit" class="btn btn-primary">Add</button> </div> </form></pre> <p>In my /todo/add URL I have a php script assigned to that route and it just echoes a string to see if the form hits the URL, but it doesn't, it just Stay on the same page with parameters. </p>
P粉674876385P粉674876385390 days ago470

reply all(2)I'll reply

  • P粉594941301

    P粉5949413012023-08-29 17:52:01

    Put action='' and method='' in the form tag instead of the div tag

    reply
    0
  • P粉937769356

    P粉9377693562023-08-29 14:10:17

    You almost did it. All you need to do is move the "action" and "method" attributes into the form tag, not the div tag.

    Since you don't have "action" in the form tag, the default behavior is to submit the form to the same page.

    reply
    0
  • Cancelreply