M
M
Marat Ivanov2019-06-13 18:29:56
JavaScript
Marat Ivanov, 2019-06-13 18:29:56

How to write users into an array from the form in state?

Tell me how to correctly form an array with users (list) entered through the form in the state to send it to the server?

class SignIn extends Component {
  state = {
    name: "",
    organization: "",
    email: "",
    current:"",
    phone: "",
    simulator: "",
    error: "",
    list: []
  };
  componentDidMount() {
    auth.logout();
  }

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


  };
  onSubmit = e => {
    e.preventDefault();
    const { name } = this.state;
    localStorage.clear();
    localStorage.setItem("userName", name);
    const local = localStorage.getItem("userName");
  };

  render() {
    const { classes } = this.props;
    return (
        <main className={classes.main}>
          <CssBaseline />
          <Paper className={classes.paper}>
          <form className={classes.form} onSubmit={this.onSubmit}>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="name">Фамилия Имя Отчество</InputLabel>
                <Input
                    id="name"
                    name="name"
                    autoComplete="name"
                    autoFocus
                    onChange={this.handleChange}
                />
              </FormControl>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="organization">Название компании</InputLabel>
                <Input
                    id="organization"
                    name="organization"
                    autoComplete="organization"
                    onChange={this.handleChange}
                />
              </FormControl>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="email">E-MAIL</InputLabel>
                <Input
                    id="email"
                    name="email"
                    autoComplete="email"
                    onChange={this.handleChange}
                />
              </FormControl>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="current">Должность</InputLabel>
                <Input
                    id="current"
                    name="current"
                    autoComplete="current"
                    onChange={this.handleChange}
                />
              </FormControl>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="phone">Телефон</InputLabel>
                <Input
                    id="phone"
                    name="phone"
                    autoComplete="phone"
                    onChange={this.handleChange}
                />
              </FormControl>
              <FormControl margin="normal" required fullWidth>
                <InputLabel htmlFor="simulator">Какой тренажер нужен?</InputLabel>
                <Input
                    id="simulator"
                    name="simulator"
                    autoComplete="simulator"
                    onChange={this.handleChange}
                />
              </FormControl>
              <Button
                  type="submit"
                  fullWidth
                  variant="contained"
                  color="primary"
                  className={classes.submit}
              >
                Записать пользователя
              </Button>
            </form>
          </Paper>
        </main>
    );
  }
}
export default withStyles(styles)(SignIn);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question