Advertisement
Guest User

regform

a guest
May 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import http from 'axios'
  3.  
  4. class RegistrationForm extends Component {
  5.  
  6. constructor(props) {
  7. super(props)
  8.  
  9. this.state = {
  10. firstname: '',
  11. lastname: '',
  12. email: '',
  13. password: '',
  14. addressline: '',
  15. zipcode: '',
  16. city: '',
  17. country: 'Kycklingfarmen',
  18. termsaccept: ''
  19. }
  20. }
  21.  
  22. handleChange = (event) => {
  23. this.setState({ [event.target.id]: event.target.value })
  24. }
  25.  
  26. handleSubmit = (e) => {
  27. e.preventDefault()
  28.  
  29. http
  30. .post('http://localhost:3001/api/users/register', this.state)
  31. .then(res => console.log(res))
  32. .then(() => this.props.history.push('/login'))
  33. .catch(error => console.log(error))
  34. }
  35.  
  36. render() {
  37.  
  38. const { firstname, lastname, email, password, addressline, zipcode, city, country, termsaccept } = this.state
  39.  
  40. return (
  41. <form noValidate onSubmit={this.handleSubmit}>
  42.  
  43. <div className="form-row">
  44. <div className="form-group col-md-6">
  45. <label htmlFor="firstname">First Name</label>
  46. <input type="text" className="form-control" id="firstname" placeholder="First Name" value={firstname}
  47. onChange={this.handleChange} />
  48. </div>
  49.  
  50. <div className="form-group col-md-6">
  51. <label htmlFor="lastname">Last Name</label>
  52. <input type="text" className="form-control" id="lastname" placeholder="Last Name" value={lastname}
  53. onChange={this.handleChange} />
  54. </div>
  55. </div>
  56.  
  57. <div className="form-row">
  58. <div className="form-group col-md-6">
  59. <label htmlFor="email">Email</label>
  60. <input type="email" className="form-control" id="email" placeholder="Email" value={email}
  61. onChange={this.handleChange} />
  62. </div>
  63.  
  64. <div className="form-group col-md-6">
  65. <label htmlFor="password">Password</label>
  66. <input type="password" className="form-control" id="password" placeholder="Password" value={password}
  67. onChange={this.handleChange} />
  68. </div>
  69. </div>
  70.  
  71.  
  72. <div className="form-group">
  73. <label htmlFor="addressline">Address</label>
  74. <input type="text" className="form-control" id="addressline" placeholder="1234 Main St" value={addressline}
  75. onChange={this.handleChange} />
  76. </div>
  77.  
  78.  
  79. <div className="form-row">
  80. <div className="form-group col-md-2">
  81. <label htmlFor="zipcode">Zip</label>
  82. <input type="text" className="form-control" id="zipcode" value={zipcode} onChange={this.handleChange} />
  83. </div>
  84.  
  85. <div className="form-group col-md-6">
  86. <label htmlFor="city">City</label>
  87. <input type="text" className="form-control" id="city" value={city} onChange={this.handleChange} />
  88. </div>
  89.  
  90. <div className="form-group col-md-4">
  91. <label htmlFor="country">Country</label>
  92. <select id="country" className="form-control" value={country} onChange={this.handleChange}>
  93. <option value="Kycklingfarmen">Kycklingfarmen</option>
  94. <option value="Sweeden">Sweeden</option>
  95. <option value="Finneland">Finneland</option>
  96. <option value="Norreway">Norreway</option>
  97. </select>
  98. </div>
  99. </div>
  100.  
  101.  
  102. <div className="form-group">
  103. <div className="form-check">
  104. <input className="form-check-input" type="checkbox" id="termsaccept" value={termsaccept}
  105. onChange={this.handleChange} />
  106. <label className="form-check-label" htmlFor="termsaccept">
  107. Accept the user termites!
  108. </label>
  109. </div>
  110. </div>
  111.  
  112.  
  113. <button type="submit" className="btn btn-primary">Sign Öp</button>
  114.  
  115. </form>
  116. )
  117. }
  118.  
  119. }
  120.  
  121. export default RegistrationForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement