1

sorry for the very noob question. I have a page : www.example.com/edit/3 with form inside.

<form class="" action="" method="post"> 

Usually my form action I will specify something like add, register, etc. In this case, I am not sure how do I specify it. Currently it is working when I save it if I leave it blank without specifying anything. But I am not sure is this the right way to do it.

Controller

public function edit_game(){} 

Routes

$routes->match(['get', 'post'], 'account/edit_game/(:num)', 'Addgame::edit_game/$1'); 

Can anyone advise?

2
  • 1
    In the case where action="" you can leave it out altogether. It's only needed if you want to "send" the form data "somewhere else" to another file to handle it. In the case of using form_open() and friends just set action to ''. It's all good. Commented Sep 5, 2020 at 19:43
  • @TimBrownlaw I see, so I can just leave it as it is, right? I have updated my question with my current controller as well my routes. Commented Sep 7, 2020 at 13:55

1 Answer 1

1

action="" is the URI to which send the form data, aka the controller where you treat the received data. If not specified, it will be the same page as the one you are currently on.

What you can do:

<form method="post"> </form> <form method="post" action=""> <!-- same as previous --> </form> <form method="post" action="/some/page"> </form> 

In the last example, note the leading /, it means it is according to the site root. If you forget it, it will be relative to the current URI.

Exemple, if the page containing the <form> is http://example.com/edit/3:

  • action="/some/page" will redirect to http://example.com/some/page.
  • action="some/page" will redirect to http://example.com/edit/some/page
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your advise, I have updated my question with my current controller and routes. So based on your answer, I assume I can also just leave it blank?
Yes, or even remove it completely. Side note, by setting $routes->setTranslateURIDashes(true); in app/Config/Routes.php, you can use dashes in the URL: site.com/account/edit-game/3 => Account::edit_game(3) (the - becomes a _.
Thank you for your suggestion. I tried to set it to true but it's not working though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.