Advertisement
Guest User

Untitled

a guest
Jan 30th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import axios from 'axios';
  3. import 'bootstrap/dist/css/bootstrap.min.css';
  4.  
  5. class Register extends Component {
  6.  
  7. constructor(props){
  8.  
  9. super(props);
  10.  
  11. this.state = {
  12. username: '',
  13. password: '',
  14. age: '',
  15. famille: '',
  16. race: '',
  17. nourriture: ''
  18. };
  19.  
  20. this.handleSubmitRegister = this.handleSubmitRegister.bind(this);
  21. this.handleChangeUsername = this.handleChangeUsername.bind(this);
  22. this.handleChangePassword = this.handleChangePassword.bind(this);
  23. this.handleChangeAge = this.handleChangeAge.bind(this);
  24. this.handleChangeFamille = this.handleChangeFamille.bind(this);
  25. this.handleChangeRace = this.handleChangeRace.bind(this);
  26. this.handleChangeNourriture = this.handleChangeNourriture.bind(this);
  27. }
  28.  
  29. handleChangeUsername(event) {
  30. this.setState({
  31. username: event.target.value
  32. });
  33. }
  34.  
  35. handleChangePassword(event) {
  36. this.setState({
  37. password: event.target.value
  38. });
  39. }
  40.  
  41. handleChangeAge(event) {
  42. this.setState({
  43. password: event.target.value
  44. });
  45. }
  46. handleChangeFamille(event) {
  47. this.setState({
  48. password: event.target.value
  49. });
  50. }
  51. handleChangeRace(event) {
  52. this.setState({
  53. password: event.target.value
  54. });
  55. }
  56. handleChangeNourriture(event) {
  57. this.setState({
  58. password: event.target.value
  59. });
  60. }
  61.  
  62. handleSubmitRegister(event){
  63.  
  64. event.preventDefault();
  65.  
  66. const url = "/users";
  67.  
  68. const data = {
  69. username: this.state.username,
  70. password: this.state.password
  71. }
  72.  
  73. axios.post(url, { data })
  74. alert('register with success');
  75. this.props.history.push('/connection');
  76. }
  77.  
  78. render() {
  79. return(
  80. <div className="register">
  81. <h1>Register</h1>
  82. <form id="fields" onSubmit={this.handleSubmitRegister}>
  83. <input class="form-control form-control-lg" type="text" value={this.state.username} onChange={this.handleChangeUsername} placeholder="Username" />
  84. <input class="form-control form-control-lg" type="password" name="password" value={this.state.password} onChange={this.handleChangePassword} placeholder="Password" />
  85. <input class="form-control form-control-lg" type="number" value={this.state.age} onChange={this.handleChangeAge} placeholder="Age" />
  86. <input class="form-control form-control-lg" type="text" value={this.state.famille} onChange={this.handleChangeFamille} placeholder="Famille" />
  87. <input class="form-control form-control-lg" type="text" value={this.state.race} onChange={this.handleChangeRace} placeholder="Race" />
  88. <input class="form-control form-control-lg" type="text" value={this.state.nourriture} onChange={this.handleChangeNourriture} placeholder="Nourriture" />
  89.  
  90. <input class="btn btn-outline-primary" type="submit" value="Register" name="sub" />
  91. </form>
  92. </div>
  93. );
  94. }
  95. }
  96.  
  97. export default Register;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement