Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

https://stackoverflow.com/questions/51115640/how-to-send-form-data-from-react-to-express/51116082

class Register extends Component {
  constructor(props) {
    super(props)
    this.state = {
      first_name: '',
      last_name: '',
      email: '',
      password: '',
      phone: ''
    }
  }

  onChange = (e) => {
    this.setState({ [e.target.name]: e.target.value });
  }

  onSubmit = (e) => {
    e.preventDefault();
    // get form data out of state
    const { first_name, last_name, password, email, phone } = this.state;

    fetch('http://localhost:4000/api/users/register' , {
      method: "POST",
      headers: {
        'Content-type': 'application/json'
      }
      .then((result) => {
        console.log(result)
      })
  })
}
      render() {
        const { classes } = this.props;
        const { first_name, last_name, password, email, phone } = this.state;
        return (
          <div className="session">
          <h1>Create your Account</h1>
            <div className="register-form">
              <form method='POST' action='http://localhost:4000/api/users/register'>
                <TextField label="First Name" name="first_name" />
                <br/>
                <TextField label="Last Name" name="last_name" />
                <br/>
                <TextField label="Email" name="email" />
                <br/>
                <TextField label="Password" name="password" />
                <br/>    
                <TextField label="Phone #" name="phone" />
                <Button type='Submit' variant="contained" color="primary">
                  Register
                </Button>
              </form>
            </div>
          </div>
        );
      }
    }

    export default Register;
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native getting older version assets 
Javascript :: sequelize findall in array 
Javascript :: node red using tcp request 
Javascript :: hack using javascript 
Javascript :: c# summary brackets 
Javascript :: js check if tab switched 
Javascript :: export data from iredmail 
Javascript :: CELEBRITY PROBLEM 2 gfg 7-18-21 
Javascript :: allow cookies sent by the client 
Javascript :: why browser is not detecting my current position 
Javascript :: fly: Javascript 
Javascript :: angular dynamic script loading 
Javascript :: javascript remove junk element from array 
Javascript :: Upload literal unsupported graphql 
Javascript :: blabla 
Javascript :: convert space to dash/hyphen javascript regex 
Javascript :: how to enable button of upload after click on chosefile in jquery 
Javascript :: stop interval javascript 
Javascript :: Pause interval button javascript 
Javascript :: fetch memes from redit from javascript 
Javascript :: botão delete no reactjs com class component 
Javascript :: node js validate body without middleware 
Javascript :: html css and javascript for web developers 
Javascript :: get ordinal number 
Javascript :: internation number 
Javascript :: regression to the mean using javascript 
Javascript :: Nested comparison operator in Javascript 
Javascript :: show hide pseudo element jquery 
Javascript :: nestjs forRoutes middlewarwe 
Javascript :: javascript random number between 0 and 30 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =