Guest User

Untitled

a guest
Jan 28th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.28 KB | None | 0 0
  1. <style>
  2. #sign-up-form {
  3. width: 100%;
  4. max-width: 640px;
  5. margin: 20px auto;
  6. padding: 10px;
  7. border-radius: 15px;
  8. background-color: rgba(7,30,68,1);
  9. text-align: center
  10. }
  11. @media screen and (max-width: 767px) {
  12. #sign-up-form {
  13. width: calc(100% - 40px);
  14. margin: 20px;
  15. }
  16. }
  17.  
  18. #sign-up-form span,
  19. #sign-up-form input {
  20. width: 100%;
  21. }
  22.  
  23. #sign-up-form input {
  24. margin-top: 10px;
  25. font-size: 1rem;
  26. }
  27.  
  28. #sign-up-form .form-title {
  29. font-size: 1.25rem;
  30. }
  31.  
  32. #sign-up-form .form-title,
  33. #sign-up-form label {
  34. color: #ffc90f;
  35. }
  36.  
  37. #sign-up-form input[name=first-name],
  38. #sign-up-form input[name=last-name]{
  39. width: calc(50% - 5px);
  40. float: left;
  41. }
  42. #sign-up-form input[name=first-name] {
  43. margin-right: 10px;
  44. }
  45. @media screen and (max-width: 767px) {
  46. #sign-up-form input[name=first-name],
  47. #sign-up-form input[name=last-name]{
  48. width: 100%;
  49. }
  50. #sign-up-form input[name=first-name] {
  51. margin-right: 0;
  52. }
  53. }
  54.  
  55. #sign-up-form label[for=gdpr-consent]{
  56. font-size: 0.6rem;
  57. }
  58.  
  59. #sign-up-form input[type=checkbox] {
  60. width: 20px;
  61. }
  62.  
  63. #sign-up-form input[type=submit] {
  64. width: 100%;
  65. max-width: 210px;
  66. padding: 5px;
  67. margin: 20px auto 0;
  68. position: relative;
  69.  
  70. border-radius: 15px;
  71. border: none;
  72.  
  73. -webkit-transition: all .7s;
  74. transition: all .7s;
  75.  
  76. background-color: #007dbe;
  77. color: white;
  78. font-size: 1.875rem;
  79.  
  80. cursor: pointer;
  81. outline: 0;
  82. }
  83. #sign-up-form input[type=submit]:hover {
  84. background-color: #00295b;
  85. }
  86.  
  87. .error {
  88. color: red;
  89. }
  90.  
  91. .success-log {
  92. margin-top: 20px;
  93. color: #4BB543;
  94. font-size: 16px;
  95. }
  96. </style>
  97.  
  98. <?php
  99. // show errors
  100. error_reporting(E_ALL);
  101. ini_set('display_errors', 1);
  102.  
  103. $servername = "****";
  104. $username = "****";
  105. $password = "****";
  106. $dbname = "****";
  107.  
  108. // Create connection
  109. $conn = new mysqli($servername, $username, $password, $dbname);
  110. // Check connection
  111. if ($conn->connect_error) {
  112. die("Connection failed: " . $conn->connect_error);
  113. }
  114.  
  115.  
  116. // define variables and set to empty values
  117. $firstNameErr = $lastNameErr = $emailErr = $gdprConsentErr = "";
  118. $firstname = $lastname = $email = $gdprconsent = "";
  119.  
  120. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  121. if (empty($_POST["first-name"])) {
  122. $firstNameErr = "First name is required";
  123. } else {
  124. $firstname = test_input($_POST["first-name"]);
  125.  
  126. // check if name only contains letters and whitespace
  127. if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
  128. $firstNameErr = "Only letters and white space allowed";
  129. }
  130. }
  131.  
  132. if (empty($_POST["last-name"])) {
  133. $lastNameErr = "Last name is required";
  134. } else {
  135. $lastname = test_input($_POST["last-name"]);
  136.  
  137. // check if name only contains letters and whitespace
  138. if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
  139. $lastNameErr = "Only letters and white space allowed";
  140. }
  141. }
  142.  
  143. if (empty($_POST["email"])) {
  144. $emailErr = "Email is required";
  145. } else {
  146. $email = test_input($_POST["email"]);
  147.  
  148. // check if e-mail address is well-formed
  149. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  150. $emailErr = "Invalid email format";
  151. }
  152. }
  153.  
  154. if (empty($_POST["gdpr-consent"])) {
  155. $gdprconsent = "You must give consent";
  156. } else {
  157. $gdprconsent = test_input($_POST["gdpr-consent"]);
  158. }
  159. }
  160.  
  161. function test_input($data) {
  162. $data = trim($data);
  163. $data = stripslashes($data);
  164. $data = htmlspecialchars($data);
  165. return $data;
  166. }
  167.  
  168. if (!empty($firstname) && !empty($lastname) && !empty($email) && !empty($gdprconsent)) {
  169. $sql = "INSERT INTO 'wp_email_subscribers' ('first_name', 'last_name', 'email', 'gdpr_consent') VALUES ($firstname, $lastname, $email, $gdprconsent)";
  170. $result = $conn->query($sql);
  171. $conn->query($sql);
  172.  
  173. var_dump($firstname);
  174. var_dump($lastname);
  175. var_dump($email);
  176. var_dump($gdprconsent);
  177. var_dump($sql);
  178. var_dump($result);
  179. }
  180. ?>
  181.  
  182. <div class="form-title">Sign up to our newsletter!</div>
  183.  
  184. <?php if (!isset($_POST["submit"])): ?>
  185. <form method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>" class="email-sub-form">
  186. <input type="text" name="first-name" value="<?php echo $firstname;?>" placeholder="First Name *" required>
  187. <input type="text" name="last-name" value="<?php echo $lastname;?>" placeholder="Last Name *" required>
  188. <input type="email" name="email" value="<?php echo $email;?>" placeholder="Email *" required>
  189. <input type="checkbox" name="gdpr-consent" id="gdpr-consent" value="1" required><label for="gdpr-consent">I consent to $$$$ using my data for marketing purposes.</label>
  190.  
  191. <div class="error-log">
  192. <span class="error"><?php if (!empty($firstNameErr)) { echo $firstNameErr; }?></span>
  193. <span class="error"><?php if (!empty($lastNameErr)) { echo $lastNameErr; }?></span>
  194. <span class="error"><?php if (!empty($emailErr)) { echo $emailErr; }?></span>
  195. <span class="error"><?php if (!empty($gdprConsentErr)) { echo $gdprConsentErr; }?></span>
  196. </div>
  197.  
  198. <input type="submit" name="submit" value="Submit">
  199. </form>
  200. <?php endif; ?>
  201.  
  202. <?php if (isset($_POST["submit"])): ?>
  203. <div class="success-log">
  204. <div class="success-inner">
  205. Thank you for subscribing to our e-news.<br/>
  206. You have been added into our mail list.
  207. </div>
  208. </div>
  209. <?php endif; ?>
  210.  
  211. <style>
  212. #sign-up-form {
  213. width: 100%;
  214. max-width: 640px;
  215. margin: 20px auto;
  216. padding: 10px;
  217. border-radius: 15px;
  218. background-color: rgba(7,30,68,1);
  219. text-align: center
  220. }
  221. @media screen and (max-width: 767px) {
  222. #sign-up-form {
  223. width: calc(100% - 40px);
  224. margin: 20px;
  225. }
  226. }
  227.  
  228. #sign-up-form span,
  229. #sign-up-form input {
  230. width: 100%;
  231. }
  232.  
  233. #sign-up-form input {
  234. margin-top: 10px;
  235. font-size: 1rem;
  236. }
  237.  
  238. #sign-up-form .form-title {
  239. font-size: 1.25rem;
  240. }
  241.  
  242. #sign-up-form .form-title,
  243. #sign-up-form label {
  244. color: #ffc90f;
  245. }
  246.  
  247. #sign-up-form input[name=first-name],
  248. #sign-up-form input[name=last-name]{
  249. width: calc(50% - 5px);
  250. float: left;
  251. }
  252. #sign-up-form input[name=first-name] {
  253. margin-right: 10px;
  254. }
  255. @media screen and (max-width: 767px) {
  256. #sign-up-form input[name=first-name],
  257. #sign-up-form input[name=last-name]{
  258. width: 100%;
  259. }
  260. #sign-up-form input[name=first-name] {
  261. margin-right: 0;
  262. }
  263. }
  264.  
  265. #sign-up-form label[for=gdpr-consent]{
  266. font-size: 0.6rem;
  267. }
  268.  
  269. #sign-up-form input[type=checkbox] {
  270. width: 20px;
  271. }
  272.  
  273. #sign-up-form input[type=submit] {
  274. width: 100%;
  275. max-width: 210px;
  276. padding: 5px;
  277. margin: 20px auto 0;
  278. position: relative;
  279.  
  280. border-radius: 15px;
  281. border: none;
  282.  
  283. -webkit-transition: all .7s;
  284. transition: all .7s;
  285.  
  286. background-color: #007dbe;
  287. color: white;
  288. font-size: 1.875rem;
  289.  
  290. cursor: pointer;
  291. outline: 0;
  292. }
  293. #sign-up-form input[type=submit]:hover {
  294. background-color: #00295b;
  295. }
  296.  
  297. .error {
  298. color: red;
  299. }
  300.  
  301. .success-log {
  302. margin-top: 20px;
  303. color: #4BB543;
  304. font-size: 16px;
  305. }
  306. </style>
  307.  
  308. <?php
  309. // show errors
  310. error_reporting(E_ALL);
  311. ini_set('display_errors', 1);
  312.  
  313. global $wpdb;
  314.  
  315. /*
  316. $servername = "****";
  317. $username = "****";
  318. $password = "****";
  319. $dbname = "****";
  320.  
  321. // Create connection
  322. $conn = new mysqli($servername, $username, $password, $dbname);
  323. // Check connection
  324. if ($conn->connect_error) {
  325. die("Connection failed: " . $conn->connect_error);
  326. }
  327. */
  328.  
  329.  
  330. // define variables and set to empty values
  331. $firstNameErr = $lastNameErr = $emailErr = $gdprConsentErr = "";
  332. $firstname = $lastname = $email = $gdprconsent = "";
  333.  
  334. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  335. if (empty($_POST["first-name"])) {
  336. $firstNameErr = "First name is required";
  337. } else {
  338. $firstname = test_input($_POST["first-name"]);
  339.  
  340. // check if name only contains letters and whitespace
  341. if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
  342. $firstNameErr = "Only letters and white space allowed";
  343. }
  344. }
  345.  
  346. if (empty($_POST["last-name"])) {
  347. $lastNameErr = "Last name is required";
  348. } else {
  349. $lastname = test_input($_POST["last-name"]);
  350.  
  351. // check if name only contains letters and whitespace
  352. if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
  353. $lastNameErr = "Only letters and white space allowed";
  354. }
  355. }
  356.  
  357. if (empty($_POST["email"])) {
  358. $emailErr = "Email is required";
  359. } else {
  360. $email = test_input($_POST["email"]);
  361.  
  362. // check if e-mail address is well-formed
  363. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  364. $emailErr = "Invalid email format";
  365. }
  366. }
  367.  
  368. if (empty($_POST["gdpr-consent"])) {
  369. $gdprconsent = "You must give consent";
  370. } else {
  371. $gdprconsent = test_input($_POST["gdpr-consent"]);
  372. }
  373. }
  374.  
  375. function test_input($data) {
  376. $data = trim($data);
  377. $data = stripslashes($data);
  378. $data = htmlspecialchars($data);
  379. return $data;
  380. }
  381.  
  382. $table = 'wp_email_subscribers';
  383. $data = array(
  384. 'first_name' => $firstname,
  385. 'last_name' => $lastname,
  386. 'email'=> $email ,
  387. 'gdpr_consent'=>$gdprconsent
  388. );
  389. $format = array('%s','%s', '%s', '%s');
  390. $wpdb->insert($table,$data,$format);
  391. var_dump($wpdb->insert_id);
  392.  
  393. /*if (!empty($firstname) && !empty($lastname) && !empty($email) && !empty($gdprconsent)) {
  394. $sql = "INSERT INTO `wp_email_subscribers` (`first_name`, `last_name`, `email`, `gdpr_consent`) VALUES ($firstname, $lastname, $email, $gdprconsent)";
  395. $result = $conn->query($sql);
  396. $conn->query($sql);
  397.  
  398. var_dump($firstname);
  399. var_dump($lastname);
  400. var_dump($email);
  401. var_dump($gdprconsent);
  402. var_dump($sql);
  403. var_dump($result);
  404. }*/
  405. ?>
  406.  
  407. <div class="form-title">Sign up to our newsletter!</div>
  408.  
  409. <?php if (!isset($_POST["submit"])): ?>
  410. <form method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>" class="email-sub-form">
  411. <input type="text" name="first-name" value="<?php echo $firstname;?>" placeholder="First Name *" required>
  412. <input type="text" name="last-name" value="<?php echo $lastname;?>" placeholder="Last Name *" required>
  413. <input type="email" name="email" value="<?php echo $email;?>" placeholder="Email *" required>
  414. <input type="checkbox" name="gdpr-consent" id="gdpr-consent" value="1" required><label for="gdpr-consent">I consent to $$$$ using my data for marketing purposes.</label>
  415.  
  416. <div class="error-log">
  417. <span class="error"><?php if (!empty($firstNameErr)) { echo $firstNameErr; }?></span>
  418. <span class="error"><?php if (!empty($lastNameErr)) { echo $lastNameErr; }?></span>
  419. <span class="error"><?php if (!empty($emailErr)) { echo $emailErr; }?></span>
  420. <span class="error"><?php if (!empty($gdprConsentErr)) { echo $gdprConsentErr; }?></span>
  421. </div>
  422.  
  423. <input type="submit" name="submit" value="Submit">
  424. </form>
  425. <?php endif; ?>
  426.  
  427. <?php if (isset($_POST["submit"])): ?>
  428. <div class="success-log">
  429. <div class="success-inner">
  430. Thank you <?php echo $firstname . ' ' . $lastname; ?> for subscribing to our e-news.<br/>
  431. You have been added into our mail list.
  432. </div>
  433. </div>
  434. <?php endif; ?>
Add Comment
Please, Sign In to add comment