The first thing I'm struggling to figure out is if it's possible to add this PHP form to an iframe so I can drop it on several different sites (Facebook, Wordpress, personal sites etc). If not how else can I create a form that will allow me to drop the iframe code on different sites and still function correctly?
Currently my form just submits the data to my email but I want the data to also get posted and stored within a database. Can I do this within an iframe?
Below is my form..
HTML
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name
Phone: $phone
Call Back: $call
Website: $website
Priority: $priority
Type: $type
Message: $message";
$recipient = "youremail@here.com";
$subject = "Contact Form";
$mailheader = "From: $email
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Yes, you can do this.
If you host the iframe on your host, you have direct access to your database. The mail.php file should do the posting.
Use this inside your code, before or after mailing the message:
define('DBHOST', 'localhost');
define('DBNAME', '');
define('DBUSER', '');
define('DBPASS', '');
function nuukDb() {
$nuukDb = new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8', DBUSER, DBPASS);
$nuukDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$nuukDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$nuuk = $nuukDb->prepare("INSERT INTO tablename (value1, value2, value3) VALUES ('$name', '$email', '$phone')");
$nuuk->execute();
Reference: https://github.com/wolffe/nuuk