Advertisement
shadiff

tday

Apr 2nd, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 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. <div className="accounts__container">
  60. <form action ='#'>
  61. <span className="title">CONTACT DETAILS</span>
  62. <div className='fields'>
  63. <div class="input__field">
  64. <label>Sender's Full Name</label>
  65. <input type="text"
  66. placeholder="Enter full name"
  67. onChange={handleChange}
  68. value={ContactData.sfull_name}
  69. name="Full Names"
  70. required/>
  71. </div>
  72.  
  73. <div class="input__field">
  74. <label>Sender's ID/ems NUMBER</label>
  75. <input type="text"
  76. placeholder="Enter your NO."
  77. onChange={handleChange}
  78. value={ContactData.id}
  79. required/>
  80. </div>
  81.  
  82. <div class="input__field">
  83. <label> Sender's Email</label>
  84. <input type="text"
  85. placeholder="Enter Email"
  86. onChange={handleChange}
  87. value={ContactData.email}
  88. required/>
  89. </div>
  90.  
  91. <div class="input__field">
  92. <label>Sender's Phone Number</label>
  93. <input type="text"
  94. placeholder="Enter phone number"
  95. onChange={handleChange}
  96. value={ContactData.phone}
  97. required/>
  98. </div>
  99.  
  100. <div class="input__field">
  101. <label> Recipient's Full Name</label>
  102. <input type="text"
  103. onChange={handleChange}
  104. value={ContactData.rfull_name}
  105. placeholder="Enter full name"
  106. required/>
  107. </div>
  108.  
  109. <div class="input__field">
  110. <label>Recipent's ID/ems NUMBER</label>
  111. <input type="text"
  112. placeholder="Enter your NO."
  113. onChange={handleChange}
  114. value={ContactData.rno}
  115. required/>
  116. </div>
  117. <div class="input__field">
  118. <label>Recipent's PHONE NUMBER</label>
  119. <input type="text"
  120. onChange={handleChange}
  121. value={ContactData.rphone}
  122. placeholder="Enter your NO."
  123. required/>
  124. </div>
  125. </div>
  126. </form>
  127. </div>
  128. </>
  129. )
  130. }
  131.  
  132. export default Personal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement