From 62a8228eea4e72db9c68eb44e59c8bc5c2e02a3d Mon Sep 17 00:00:00 2001 From: Charles Stephen Thompson Date: Thu, 22 Feb 2024 07:58:48 +0000 Subject: [PATCH] contact form edits --- .../vendor/php-email-form/php-email-form.php | 42 +++++++++ assets/vendor/php-email-form/validate.js | 85 +++++++++++++++++ forms/Readme.txt | 2 + forms/contact.php | 41 +++++++++ index.html | 92 +++++++++++++------ 5 files changed, 232 insertions(+), 30 deletions(-) create mode 100644 assets/vendor/php-email-form/php-email-form.php create mode 100755 assets/vendor/php-email-form/validate.js create mode 100755 forms/Readme.txt create mode 100755 forms/contact.php diff --git a/assets/vendor/php-email-form/php-email-form.php b/assets/vendor/php-email-form/php-email-form.php new file mode 100644 index 0000000..f958bac --- /dev/null +++ b/assets/vendor/php-email-form/php-email-form.php @@ -0,0 +1,42 @@ + '', 'subjectMessage' => '', 'messageMessage' => '', 'antispamMessage' => ''); + + if(!isEmail($clientEmail)) { + $array['emailMessage'] = 'Invalid email!'; + } + if($subject == '') { + $array['subjectMessage'] = 'Empty subject!'; + } + if($message == '') { + $array['messageMessage'] = 'Empty message!'; + } + if($antispam != '12') { + $array['antispamMessage'] = 'Wrong antispam answer!'; + } + if(isEmail($clientEmail) && $subject != '' && $message != '' && $antispam == '12') { + // Send email + $headers = "From: " . $clientEmail . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail; + mail($emailTo, $subject . " (bootstrap contact form tutorial)", $message, $headers); + } + + echo json_encode($array); + +} + +?> diff --git a/assets/vendor/php-email-form/validate.js b/assets/vendor/php-email-form/validate.js new file mode 100755 index 0000000..d42b6aa --- /dev/null +++ b/assets/vendor/php-email-form/validate.js @@ -0,0 +1,85 @@ +/** +* PHP Email Form Validation - v3.7 +* URL: https://bootstrapmade.com/php-email-form/ +* Author: BootstrapMade.com +*/ +(function () { + "use strict"; + + let forms = document.querySelectorAll('.php-email-form'); + + forms.forEach( function(e) { + e.addEventListener('submit', function(event) { + event.preventDefault(); + + let thisForm = this; + + let action = thisForm.getAttribute('action'); + let recaptcha = thisForm.getAttribute('data-recaptcha-site-key'); + + if( ! action ) { + displayError(thisForm, 'The form action property is not set!'); + return; + } + thisForm.querySelector('.loading').classList.add('d-block'); + thisForm.querySelector('.error-message').classList.remove('d-block'); + thisForm.querySelector('.sent-message').classList.remove('d-block'); + + let formData = new FormData( thisForm ); + + if ( recaptcha ) { + if(typeof grecaptcha !== "undefined" ) { + grecaptcha.ready(function() { + try { + grecaptcha.execute(recaptcha, {action: 'php_email_form_submit'}) + .then(token => { + formData.set('recaptcha-response', token); + php_email_form_submit(thisForm, action, formData); + }) + } catch(error) { + displayError(thisForm, error); + } + }); + } else { + displayError(thisForm, 'The reCaptcha javascript API url is not loaded!') + } + } else { + php_email_form_submit(thisForm, action, formData); + } + }); + }); + + function php_email_form_submit(thisForm, action, formData) { + fetch(action, { + method: 'POST', + body: formData, + headers: {'X-Requested-With': 'XMLHttpRequest'} + }) + .then(response => { + if( response.ok ) { + return response.text(); + } else { + throw new Error(`${response.status} ${response.statusText} ${response.url}`); + } + }) + .then(data => { + thisForm.querySelector('.loading').classList.remove('d-block'); + if (data.trim() == 'OK') { + thisForm.querySelector('.sent-message').classList.add('d-block'); + thisForm.reset(); + } else { + throw new Error(data ? data : 'Form submission failed and no error message returned from: ' + action); + } + }) + .catch((error) => { + displayError(thisForm, error); + }); + } + + function displayError(thisForm, error) { + thisForm.querySelector('.loading').classList.remove('d-block'); + thisForm.querySelector('.error-message').innerHTML = error; + thisForm.querySelector('.error-message').classList.add('d-block'); + } + +})(); diff --git a/forms/Readme.txt b/forms/Readme.txt new file mode 100755 index 0000000..da60f71 --- /dev/null +++ b/forms/Readme.txt @@ -0,0 +1,2 @@ +Fully working PHP/AJAX contact form script is available in the pro version of the template. +You can buy it from: https://bootstrapmade.com/iportfolio-bootstrap-portfolio-websites-template/ \ No newline at end of file diff --git a/forms/contact.php b/forms/contact.php new file mode 100755 index 0000000..accf64c --- /dev/null +++ b/forms/contact.php @@ -0,0 +1,41 @@ +ajax = true; + + $contact->to = $receiving_email_address; + $contact->from_name = $_POST['name']; + $contact->from_email = $_POST['email']; + $contact->subject = $_POST['subject']; + + // Uncomment below code if you want to use SMTP to send emails. You need to enter your correct SMTP credentials + /* + $contact->smtp = array( + 'host' => 'example.com', + 'username' => 'example', + 'password' => 'pass', + 'port' => '587' + ); + */ + + $contact->add_message( $_POST['name'], 'From'); + $contact->add_message( $_POST['email'], 'Email'); + $contact->add_message( $_POST['message'], 'Message', 10); + + echo $contact->send(); +?> diff --git a/index.html b/index.html index fd43d34..c201ea4 100644 --- a/index.html +++ b/index.html @@ -537,43 +537,75 @@
Jan 2012 - Jan 2013
- -
-
-
-

Contact

-

- If you feel the need to reach out, my contact information is below - and I do freelance work often. Hit me up. -

-
+ +
+
-
-
-
-
- -

Location:

-

Brooklyn, NY 11238

-
+
+

Contact

+

Feel free to hit me up as I do freelance work often.

+
+ +
+ +
+
+
+ +

Location:

+

565 Prospect Place, Brooklyn, NY 11238

+
+ + + +
+ +

Call:

+

+1.646.902.1485

+
+ + +
- -
- -

Call:

-

+1.646.902.1485

+
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
Loading
+
+
Your message has been sent. Thank you!
+
+
+
+
+
-
-
-
- +