Bladeren bron

Merge pull request #6 from sysadminwatdo/form-handlers

Form handlers
David Miller 8 jaren geleden
bovenliggende
commit
f3be331caf
3 gewijzigde bestanden met toevoegingen van 62 en 1 verwijderingen
  1. 2 1
      README.md
  2. 20 0
      form-handler-nodb.php
  3. 40 0
      form-handler.php

+ 2 - 1
README.md

@@ -8,6 +8,7 @@ To begin using this template, choose one of the following options to get started
 * [Download the latest release on Start Bootstrap](http://startbootstrap.com/template-overviews/business-casual/)
 * Clone the repo: `git clone https://github.com/BlackrockDigital/startbootstrap-business-casual.git`
 * Fork the repo
+* Your must enter your database information and your email in form-handler.php - if you don't have a database, that's fine.  Edit contact.html to direct the form to form-handler-nodb.php and emails will be sent with no database writes.
 
 ## Bugs and Issues
 
@@ -24,4 +25,4 @@ Start Bootstrap is based on the [Bootstrap](http://getbootstrap.com/) framework
 
 ## Copyright and License
 
-Copyright 2013-2016 Blackrock Digital LLC. Code released under the [MIT](https://github.com/BlackrockDigital/startbootstrap-business-casual/blob/gh-pages/LICENSE) license.
+Copyright 2013-2016 Blackrock Digital LLC. Code released under the [MIT](https://github.com/BlackrockDigital/startbootstrap-business-casual/blob/gh-pages/LICENSE) license.

+ 20 - 0
form-handler-nodb.php

@@ -0,0 +1,20 @@
+<?php
+// Emails form data to you and the person submitting the form
+// This version requires no database.
+// Set your email below
+$myemail = "ENTER_YOUR_EMAIL_HERE"; // Replace with your email, please
+
+// Receive and sanitize input
+$name = $_POST['name'];
+$email = $_POST['email'];
+$phone = $_POST['phone'];
+$message = $_POST['message'];
+
+// set up email
+$msg = "New contact form submission!\nName: " . $name . "\nEmail: " . $email . "\nPhone: " . $phone . "\nEmail: " . $email;
+$msg = wordwrap($msg,70);
+mail($myemail,"New Form Submission",$msg);
+mail($email,"Thank you for your form submission",$msg);
+echo 'Thank you for your submission.  Please <a href="index.html">Click here to return to our homepage.';
+
+?>

+ 40 - 0
form-handler.php

@@ -0,0 +1,40 @@
+<?php
+// Emails form data to you and the person submitting the form and adds it to a database
+
+// Test for db
+$db = new mysqli("DB_HOST","DB_USER","DB_PASSWORD","DB_NAME");
+$sql = "SELECT id FROM form_submissions";
+$result = $db->query($sql);
+if (empty($result)) {
+	$sql = "CREATE TABLE `form_submissions` (
+		`id` int(11) NOT NULL AUTO_INCREMENT,
+		`name` text COLLATE utf8_unicode_ci,
+		`phone` text COLLATE utf8_unicode_ci,
+		 `email` int(11) DEFAULT NULL,
+		 `message` text COLLATE utf8_unicode_ci,
+		 `submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+		 PRIMARY KEY (`id`)
+		 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+		$result = $db->query($sql);
+}
+// Set your email below
+$myemail = "ENTER_YOUR_EMAIL_HERE"; // Replace with your email
+
+// Receive and sanitize input
+$name = mysqli_real_escape_string($db, $_POST['name']);
+$email = mysqli_real_escape_string($db, $_POST['email']);
+$phone = mysqli_real_escape_string($db, $_POST['phone']);
+$message = mysqli_real_escape_string($db, $_POST['message']);
+
+// write to db
+$sql = "INSERT INTO form_submissions (name,phone,email,message) VALUES ('$name','$phone','$email','$message')";
+$result = $db->query($sql);
+
+// set up email
+$msg = "New contact form submission!\nName: " . $name . "\nEmail: " . $email . "\nPhone: " . $phone . "\nEmail: " . $email;
+$msg = wordwrap($msg,70);
+mail($myemail,"New Form Submission",$msg);
+mail($email,"Thank you for your form submission",$msg);
+echo 'Thank you for your submission.  Please <a href="index.html">Click here to return to our homepage.';
+
+?>