简体   繁体   English

使用 React、Axios 和 PHP 后端进行用户注册

[英]User registration with React, Axios and PHP backend

I need to register a new user with API.我需要使用 API 注册一个新用户。 Back-end developer gave me screenshot how he implemented registration on PhP.后端开发人员给了我他如何在 PhP 上实现注册的截图。 Unfortunately, he doesn't know react so he can't help me.不幸的是,他不知道反应所以他无法帮助我。 I already have input forms saving them in state.我已经有输入表单将它们保存在状态中。 Could you please help me what's going on in the picture below and how make registration on React.你能帮我看看下图中发生了什么以及如何在 React 上注册。

在此处输入图片说明

and my code.和我的代码。 Let me know if I missing any field.如果我遗漏了任何字段,请告诉我。 I have url , but I dont know where to add user/create, company/create links:我有 url ,但我不知道在哪里添加用户/创建、公司/创建链接:

signUp(event) {
    event.preventDefault()
    const formdata = new FormData()
    formdata.append("email", this.state.userLogin.email)
    formdata.append("password", this.state.userLogin.password)
    formdata.append("name", this.state.userLogin.name)
    formdata.append("companyName", this.state.userLogin.companyName)
    formdata.append("region", this.state.userLogin.region)
    axios
      .post("http://dev.***********.com/", formdata)
      .then(res => {
        if (res.data) {
          console.log('success')
          this.props.history.push("/settings")
        }
      })
      .catch(error => {
        console.log(error)
      })
  }

you are missing some fields for the post request, but this is how I would do it:您缺少 post 请求的一些字段,但我会这样做:

const data = {
  username: YOU_NEED_THIS,
  label: YOU_NEED_THIS,
  label_short: YOU_NEED_THIS,

  email: this.state.userLogin.email,
  password: this.state.userLogin.password,
  name: this.state.userLogin.name,
  companyName: this.state.userLogin.companyName,
  region: this.state.userLogin.region,
};

axios
  .post("http://dev.***********.com/", data)
  .then(.....)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM