未触发的ANTD形式或动作属性

发布于 2025-02-08 20:23:07 字数 1778 浏览 0 评论 0原文

我有一个登录表单,该表格单击数据应将数据发送到后端。我使用ANT设计和表单操作属性,我正在传递服务URL (action = {url})将发送数据的位置。但是,当我单击“提交”按钮时,什么也不会发生。我尝试将ANTD表单与ANTD表单控制器(例如Form.Sorm.Item和Input组件)更改为使用HTML表单,并提交数据。我怀疑问题在ANTD Action 属性中。如何使用操作属性制作ANTD表单以提交数据?


           const handleSubmit = (val) => {
               console.log("Values : ", val);
           };


           <Form
              name="login"
              layout="vertical"
              autoComplete="off"
              action={url}
              method="post"
              onFinish={handleSubmit}
            >
                 <Form.Item
                      htmlFor="username"
                      label="Username"
                      name="username"
                      rules={[
                        {
                          required: true,
                          message: `Please input your username!`,
                        },
                      ]}
                    >

                  <Input/>
               </Form.Item>
               <Form.Item
                      htmlFor="password"
                      label="Password"
                      name="password"
                      rules={[
                        {
                          required: true,
                          message: `Please input your password!`,
                        },
                      ]}
                    >

                  <Input.Password/>
               </Form.Item>
               <Button
                  size="large"
                  htmlType="submit"
                  name="login"
                  id="login-btn"
                >
                  Login
                </Button>
          </Form>

I have a login form where on button click data should be sent to the backend. I use ant design and on Form action attribute I am passing the service url (action={url}) where the data will be sent. However, when I click the submit button, nothing happens. I tried changing the antd form to use html form with antd form controllers, like Form.Item and Input components and the data get submitted. I suspect that the problem is within antd action attribute. How can I make an antD Form to submit the data using the action attribute?


           const handleSubmit = (val) => {
               console.log("Values : ", val);
           };


           <Form
              name="login"
              layout="vertical"
              autoComplete="off"
              action={url}
              method="post"
              onFinish={handleSubmit}
            >
                 <Form.Item
                      htmlFor="username"
                      label="Username"
                      name="username"
                      rules={[
                        {
                          required: true,
                          message: `Please input your username!`,
                        },
                      ]}
                    >

                  <Input/>
               </Form.Item>
               <Form.Item
                      htmlFor="password"
                      label="Password"
                      name="password"
                      rules={[
                        {
                          required: true,
                          message: `Please input your password!`,
                        },
                      ]}
                    >

                  <Input.Password/>
               </Form.Item>
               <Button
                  size="large"
                  htmlType="submit"
                  name="login"
                  id="login-btn"
                >
                  Login
                </Button>
          </Form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘人皮目录ツ 2025-02-15 20:23:07

您应该在handlesubmit函数内发送请求,并使用 fetch api 或http客户端,例如 axios (推荐)。
Axios的一个例子:

const handleSubmit = (values) => {
 axios.post(url,values).then((response) => {
  console.log(response);
 }).catch((error) => {
  console.log(error);
 })
};

You should send the request inside your handleSubmit function using Fetch API or an HTTP client like axios (recommended).
An example with axios:

const handleSubmit = (values) => {
 axios.post(url,values).then((response) => {
  console.log(response);
 }).catch((error) => {
  console.log(error);
 })
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文