search

Home  >  Q&A  >  body text

node.js - 表单里面Action是可以设别名吗?

我在研究Nodeclub代码,其实看到更新setting这个页面。

<form id='change_pass_form' action='/setting' method='post'> .... <input type='hidden' id='action' name='action' value='change_setting' /> </form>

然后Controller那里
//......
var action = req.body.action;
if (action === 'change_setting') {

}
//......

这是为什么不是判断action等于setting,是别名?

怪我咯怪我咯2864 days ago588

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 11:05:56

    You are mistaken.
    "/setting" in the form and the action you mentioned are two different things.
    The way /setting is written is a URL abbreviation. If your domain name is mydomain.com, then "/setting" is equivalent to "http://mydomain.com/setting",这是一个url。
    In your controller, action=req.body.action should get the value of the form field whose name is equal to action in the form.
    In your example, it is to get the value of the following hidden field:

    <input type='hidden' id='action' name='action' value='change_password' /> 
    

    In fact, action is equivalent to getting the action value in post data, which for php is $_post['action'].

    ps: The value of action here is change_password, not change_setting. So are you looking for the wrong processing logic after form submission?

    reply
    0
  • Cancelreply