Advertisement
shadiff

form

Apr 2nd, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.19 KB | None | 0 0
  1. import React, {useState} from 'react';
  2. import axios from 'axios';
  3. import './forms.css';
  4.  
  5. const baseUrl = '';
  6.  
  7.  
  8. const Personal = () => {
  9. const [ContactData, setContactData] = useState({
  10. 'sfull_name': '',
  11. 'rfull_name': '',
  12. 'semail': '',
  13. 'remail': '',
  14. 'sphone': '',
  15. 'rphone': '',
  16. 'package_details': '',
  17. 'submission': '',
  18. 'status': ''
  19. });
  20. const handleChange=(event) => {
  21. setContactData({
  22. ...ContactData,
  23. [event.target.name]: event.target.value
  24. })
  25. }
  26.  
  27. const submitForm=()=> {
  28. const contactFormData = new FormData();
  29. contactFormData.append("sfull_name", ContactData.s_full_name)
  30. contactFormData.append("rfull_name", ContactData.r_full_name)
  31. contactFormData.append('s_email', ContactData.s_email)
  32. contactFormData.append('r_email', ContactData.r_email)
  33. contactFormData.append('r_phone', ContactData.r_phone)
  34. contactFormData.append('s_phone', ContactData.s_phone)
  35. contactFormData.append('package_details', ContactData.package_details)
  36. contactFormData.append('submission', ContactData.submission)
  37.  
  38. try {
  39. axios.post(baseUrl, contactFormData).then((response) =>{
  40. setContactData({
  41. 'sfull_name': '',
  42. 'rfull_name': '',
  43. 'semail': '',
  44. 'remail': '',
  45. 'sphone': '',
  46. 'rphone': '',
  47. 'package_details': '',
  48. 'status': 'success'
  49. });
  50. });
  51. } catch(error){
  52. console.log(error);
  53. setContactData({'status': 'error'})
  54.  
  55. }
  56. }
  57. return (
  58. <>
  59. <section className='form_sect'>
  60. <div className='form__section'>
  61. <div className="accounts__container">
  62. <form action ='#'>
  63. <div className='form first'>
  64.  
  65. <span className="title">CONTACT DETAILS</span>
  66. <div className='fields'>
  67. <div class="input__field">
  68. <label>Sender's Full Name</label>
  69. <input type="text"
  70. placeholder="Enter full name"
  71. onChange={handleChange}
  72. value={ContactData.sfull_name}
  73. name="Full Names"
  74. required/>
  75. </div>
  76.  
  77. <div class="input__field">
  78. <label>Sender's ID/ems NUMBER</label>
  79. <input type="text"
  80. placeholder="Enter your NO."
  81. onChange={handleChange}
  82. value={ContactData.id}
  83. required/>
  84. </div>
  85.  
  86. <div class="input__field">
  87. <label> Sender's Email</label>
  88. <input type="text"
  89. placeholder="Enter Email"
  90. onChange={handleChange}
  91. value={ContactData.email}
  92. required/>
  93. </div>
  94.  
  95. <div class="input__field">
  96. <label>Sender's Phone Number</label>
  97. <input type="text"
  98. placeholder="Enter phone number"
  99. onChange={handleChange}
  100. value={ContactData.phone}
  101. required/>
  102. </div>
  103.  
  104. <div class="input__field">
  105. <label> Recipient's Full Name</label>
  106. <input type="text"
  107. onChange={handleChange}
  108. value={ContactData.rfull_name}
  109. placeholder="Enter full name"
  110. required/>
  111. </div>
  112.  
  113. <div class="input__field">
  114. <label>Recipent's ID/ems NUMBER</label>
  115. <input type="text"
  116. placeholder="Enter your NO."
  117. onChange={handleChange}
  118. value={ContactData.rno}
  119. required/>
  120. </div>
  121. <div class="input__field">
  122. <label>Recipent's PHONE NUMBER</label>
  123. <input type="text"
  124. onChange={handleChange}
  125. value={ContactData.rphone}
  126. placeholder="Enter your NO."
  127. required/>
  128. </div>
  129. </div>
  130. </div>
  131.  
  132. <div className='form second'>
  133. <div className="details-package">
  134. <span className="title">PACKAGE DETAILS</span>
  135. <div className='fields'>
  136. <div class="input__field">
  137. <label>Sender's Full Name</label>
  138. <input type="text"
  139. placeholder="Enter full name"
  140. onChange={handleChange}
  141. value={ContactData.sfull_name}
  142. name="Full Names"
  143. required/>
  144. </div>
  145.  
  146. <div class="input__field">
  147. <label>Sender's ID/ems NUMBER</label>
  148. <input type="text"
  149. placeholder="Enter your NO."
  150. onChange={handleChange}
  151. value={ContactData.id}
  152. required/>
  153. </div>
  154.  
  155. <div class="input__field">
  156. <label> Sender's Email</label>
  157. <input type="text"
  158. placeholder="Enter Email"
  159. onChange={handleChange}
  160. value={ContactData.email}
  161. required/>
  162. </div>
  163.  
  164. <div class="input__field">
  165. <label>Sender's Phone Number</label>
  166. <input type="text"
  167. placeholder="Enter phone number"
  168. onChange={handleChange}
  169. value={ContactData.phone}
  170. required/>
  171. </div>
  172.  
  173. <div class="input__field">
  174. <label> Recipient's Full Name</label>
  175. <input type="text"
  176. onChange={handleChange}
  177. value={ContactData.rfull_name}
  178. placeholder="Enter full name"
  179. required/>
  180. </div>
  181.  
  182. <div class="input__field">
  183. <label>Recipent's ID/ems NUMBER</label>
  184. <input type="text"
  185. placeholder="Enter your NO."
  186. onChange={handleChange}
  187. value={ContactData.rno}
  188. required/>
  189. </div>
  190. <div class="input__field">
  191. <label>Recipent's PHONE NUMBER</label>
  192. <input type="text"
  193. onChange={handleChange}
  194. value={ContactData.rphone}
  195. placeholder="Enter your NO."
  196. required/>
  197. </div>
  198. </div>
  199. </div>
  200. <div className='buttons'>
  201. <button className='backBtn'>
  202. <span className='btnText'>Back</span>
  203. </button>
  204.  
  205. <button className='nxtBtn'>
  206. <span className='btnText'>Next</span>
  207. </button>
  208.  
  209. </div>
  210. </div>
  211. </form>
  212. </div>
  213. </div>
  214. </section>
  215. </>
  216. )
  217. }
  218.  
  219. export default Personal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement