EDITED
Anyone/Everyone,
Can anyone help me to locate a php form for a competition I am running.
I need people to be able to pick an answer to a question (radio buttons) and then input their details (Address Line 1, Address Line 2, City, Postal Code, E-mail address and Full name) then a tick box to have them subscribe to my newsletter.
I have a code for a newsletter sign up for, that I was trying to modify but I have failed. Boo Hoo.
Can anyone help me? Perhaps even just to assist me in modifying the code I already have?
Code:
<?php
function pageRefreshed(){
if($_SERVER['HTTP_CACHE_CONTROL'] == 'max-age=0')
return true;
return false;
}
$mailType2Checked = " checked=\"checked\"";
$mailEmail = "Email Address";
if ((!pageRefreshed()) && ($_POST['s'] == 1)) {
$valid = true;
$mailEmail = trim(htmlspecialchars($_POST['mailEmail']));
$mailType = intval($_POST['mailType']);
$mailType1Checked = $mailType2Checked = "";
switch ($mailType) {
case 1: $mailType = "Text"; $mailType1Checked = " checked=\"checked\""; break;
case 2: $mailType = "HTML"; $mailType2Checked = " checked=\"checked\""; break;
default: $mailType = ""; $mailType2Checked = " checked=\"checked\""; break;
}
if(empty($mailEmail) || empty($mailType)){
$valid = false;
$mailErr = "One or more of the fields were left blank. Please make sure you have filled out the form completely.";
} else {
//valid characters...
$_name = "/^[-!#$%&*+\\.\/0-9=?A-Z^_`{|}~]+";
$_host = "([-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";
if (!preg_match($_name."@".$_host.$_tlds,$mailEmail)){
$mailErr = "The email address you supplied is invalid. Please supply a valid email address.";
$valid = false;
}
}
$divstyle = "";
if($valid){
$divstyle = " style=\"display:none;\"";
$to = "your@emailhere.com";
//$to = "you@example.com";
$re = "New Mailing List Subscriber: $mailEmail $mailType";
//add From: header
$headers = "From: MadGamers System\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("omgwtfbbq");
//tell e-mail client this e-mail contains alternate versions
$headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n";
//message to people with clients who don't understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("A visitor has requested that their email address ($mailEmail) be added to the mailing list. They would like to receive $mailType emails."));
//HTML version
$headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("A visitor has requested that their email address ($mailEmail) be added to the mailing list. They would like to receive $mailType emails."));
//send message
mail($to, $re, "", $headers);
$mailSuccess = "Your email address has been successfully added to our newsletter, thank you for your interest.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Join our newsletter!</title>
</head>
<body>
<?php echo $mailErr; ?>
<div<?php echo $divstyle; ?>>
<form method="post">
<table width="">
<tr>
<td colspan="5">Please enter your email address and select the<br />format you would like to receive our newsletter in:</td>
</tr>
<tr>
<td><input type="text" name="mailEmail" value="<?php echo $mailEmail; ?>" onclick="this.select();" /></td>
<td><input type="radio" name="mailType" value="1"<?php echo $mailType1Checked; ?> /></td><td>Text</td>
<td><input type="radio" name="mailType" value="2"<?php echo $mailType2Checked; ?> /></td><td>HTML</td>
</tr>
<tr>
<td align="center" colspan="5"><input type="hidden" name="s" value="1" /><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<?php echo $mailSuccess; ?>
</body>
</html>
Is anyone able to help me ammend this to have the following fields for a competition submission form? I can't seem to get it to send when I do edit it.
Answer 1 (radio button)
Answer 2 (radio button)
Answer 3 (radio button)
E-mail address (text field)
Full Name (text field)
Address Line 1 (text field)
Address Line 2 (text field)
Town/City (text field)
Postal Code (text field)
Newsletter signup (yes/no - tickbox)
I had trouble with the functions, not with the form itself. If anyone is able to help I appreciate it.