Integrating validation with Recaptcha (or required fields) - php

I have a form below that I want to make certain fields required based on different things.
I want the following fields to be a straight forward required field with a popup alert if they're not filled in:
Name
Email
I want the phone field to be required if phone is ticked.
Address to be required if post is ticked.
How can I make the alert's pop up if things are missing but if everything is ok then send the form?
<div id="contactform">
<script type="text/javascript">
var RecaptchaOptions = {
theme : 'white'
};
</script>
<form class="form" method="POST" action="<?php the_permalink(); ?>" onsubmit="return validateCaptcha()">
<input type="hidden" name="valid" value="0" />
<table border="0" style="float:left;" width="490">
<tbody>
<tr>
<td>
<p>Name:</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="fullname" id="fullname" /></td>
</tr>
<tr>
<td>
<p>Organisation:</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="companyname" id="companyname" /></td>
</tr>
<tr>
<td>
<p>E-mail:</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>
<p>Daytime Tel:</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="tel" id="tel" /></td>
</tr>
<tr>
<td valign="top">
<p>Contact Method:</p>
</td>
<td> </td>
<td align="left" valign="top">
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Phone" id="phone" />
<label style="margin-right: 25px;">Phone</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Email" id="email" />
<label style="margin-right: 25px;">Email</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Post" id="post" />
<label style="margin-right: 25px;">Post</label>
</p>
</td>
</tr>
<tr>
<td>
<p>Address (if applicable):</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="address" id="address" /></td>
</tr>
<tr>
<td valign="top">
<p>Where did you hear about us?:</p>
</td>
<td> </td>
<td align="left" valign="top">
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="Search Engine" id="search" />
<label style="margin-right: 25px;">Search Engine</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="NPA" id="NPA" />
<label style="margin-right: 25px;">NPA</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="Advertisement" id="advertisement" />
<label style="margin-right: 25px;">Advertisement</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="Brochure" id="brochure" />
<label style="margin-right: 25px;">Brochure</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="Show" id="show" />
<label style="margin-right: 25px;">Show</label>
</p>
<p>
<input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup2[]" value="Other" id="other" />
<label style="margin-right: 25px;">Other</label>
</p>
</td>
</tr>
<tr>
<td>
<p>Please Specify:</p>
</td>
<td> </td>
<td colspan="2"><input type="text" name="specify" id="specify" /></td>
</tr>
</tbody>
</table>
<table border="0" style="float:left;margin-left:146px;" width="490">
<tbody>
<tr>
<td> </td>
<td>
<script type="text/javascript">
function validateCaptcha()
{
if ($('input[name="valid"]')) return true;
if ($('input[name="recaptcha_response_field"]').val() == "")
{
alert("Please complete the CAPTCHA field.");
return false
}
$.ajax({
url: "http://www.medilogicuk.com/wp-content/themes/default/verify.php",
type: "POST",
async:"false",
data: {
recaptcha_response_field: $('input[name="recaptcha_response_field"]').val(),
recaptcha_challenge_field: $('input[name="recaptcha_challenge_field"]').val()
},
success: function(data){
if (data == "OK")
{
$('input[name="valid"]').val(1);
$('.form').submit();
}
else
{
alert(data);
}
},
error: function(){
alert("An error occured, please try again later");
}
});
return false;
};
</script>
<?php require_once('recaptchalib.php');
$publickey = ""; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td colspan="2"><button type="submit" name="submit" value="Send message">Send message</button></td>
</tr>
</tbody>
</table>
<? if(isset($_POST['submit'])) {
$to = "rob#domain.com";
$header = 'From: info#domain.com';
$subject = "Website enquiry";
$companyname_field = $_POST['companyname'];
$fullname_field = $_POST['fullname'];
$email_field = $_POST['email'];
$tel_field = $_POST['tel'];
$address_field = $_POST['address'];
$specify_field = $_POST['specify'];
$CheckboxGroup1 = $_POST['CheckboxGroup1'];
$CheckboxGroup2 = $_POST['CheckboxGroup2'];
if( is_array($_POST['CheckboxGroup1']) ){
foreach ($_POST['CheckboxGroup1'] as $val) {
$checkbox1results .= $val.", ";
}
}
if( is_array($_POST['CheckboxGroup2']) ){
foreach ($_POST['CheckboxGroup2'] as $val) {
$checkbox2results .= $val.", ";
}
}
$body = "Hello,\n\n You have an enquiry from the website, please see the details below:\n\n Name: $fullname_field\n Company Name: $companyname_field\n E-Mail: $email_field\n Tel: $tel_field\n Method of contact: $checkbox1results\n Address: $address_field\n Hear about us?: $checkbox2results\n Specify: $specify_field\n\n Please reply to the enquiry asap.\n\n Kind Regards \n The website";
mail($to, $subject, $body, $header);
echo "</br><p style=\"color:#e41770!IMPORTANT;\">Thank you for getting in touch, we will contact you shortly.</p>";
} ?>
</form>

Okie a quick Example for you:
The Form
<html>
<body>
<form action="#" method="POST">
<input id="email" type="text" value="" />
<a id="submit" href="#">Submit Form</a>
</form>
</body>
</html>
The Jquery Part:
$(document).ready(function(){
$('a#submit').click(function(event){
event.preventDefault();
validateEmail();
})
});
function validateEmail(){
//declarations
rule = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
//check
if ($('input#email').val() === '' || !rule.test($('input#email').val())){
alert ('That is not a Valid Email Address !');
return false;
} else {
alert('validation passed! Submit the form !');
//submit the form action here
}
}
Also you can try it live here http://jsfiddle.net/XMbEK/

You already have your answer in the code:
<script type="text/javascript">
function validateCaptcha()
{
if ($('input[name="valid"]')) return true;
if ($('input[name="recaptcha_response_field"]').val() == "")
{
alert("Please complete the CAPTCHA field.");
return false
}
Add your own needs after this:
if ( phone == 'what it needs to be' )
{
if( email == 'asdasd' ) {
// all is good
} else {
alert( 'need email too' );
}
return true;
}
else
{
alert('Blah blah wrong phone');
return false;
}
etc.

Related

How to add recaptcha to mailform

The website of the wife of a deceased friend has been misused for sending spam. This is probably because ReCaptcha is not used with the registration form. The site uses Joomla 3.9.
I would like to add ReCaptcha but I have no idea how I can do that.
I hope someone can help.
I have not tried anything myself because my knowledge of PHP is not good enough to get this done.
Here is the form:
<form id="form1" action="/script/mailforms/mailsend.php" enctype="multipart/form-data" method="post"><input name="redirect" type="hidden" value="/bedankt" />
<table border="0" width="200">
<tbody>
<tr>
<td> </td>
<td><strong>Gegevens ouder/verzorger</strong></td>
<td> </td>
<td> </td>
<td><strong>Gegevens kind</strong></td>
</tr>
<tr>
<td>Voornaam</td>
<td><span id="sprytextfield1"> <label for="Naam"></label> <input id="Naam" name="Naam" type="text" /> </span></td>
<td> </td>
<td>Naam kind</td>
<td><span id="sprytextfield9"> <label for="Naam Kind"></label> <input id="Naam Kind" name="Naam Kind" type="text" /> </span></td>
</tr>
<tr>
<td>Achternaam</td>
<td><span id="sprytextfield2"> <label for="Achternaam"></label> <input id="Achternaam" name="Achternaam" type="text" /> </span></td>
<td> </td>
<td>Geslacht</td>
<td><span id="spryradio1"> <label> <input id="Geslacht_0" name="Geslacht" type="radio" value="Jongen" /> jongen</label> <br /> <label> <input id="Geslacht_1" name="Geslacht" type="radio" value="Meisje" /> meisje</label> <br /> </span></td>
</tr>
<tr>
<td>Straat + nr</td>
<td><span id="sprytextfield3"> <label for="Straat en nr"></label> <input id="Straat en nr" name="Straat en nr" type="text" /> </span></td>
<td> </td>
<td>Geboortedatum</td>
<td><span id="sprytextfield10"> <label for="Geboortedatum"></label> <input id="Geboortedatum" name="Geboortedatum" type="text" /> </span></td>
</tr>
<tr>
<td>Postcode</td>
<td><span id="sprytextfield4"> <label for="Postcode"></label> <input id="Postcode" name="Postcode" type="text" /> </span></td>
<td> </td>
<td>Schoolnaam</td>
<td><span id="sprytextfield11"> <label for="Schoolnaam"></label> <input id="Schoolnaam" name="Schoolnaam" type="text" /> </span></td>
</tr>
<tr>
<td>Woonplaats</td>
<td><span id="sprytextfield5"> <label for="Woonplaats"></label> <input id="Woonplaats" name="Woonplaats" type="text" /> </span></td>
<td> </td>
<td>Voorkeur</td>
<td><span id="spryradio2"> <br /> <label> <input id="Voorkeur_1" name="Voorkeur" type="radio" value="Woensdag" /> Woensdagmiddag (Zonnestudio)</label> <br /> </span></td>
</tr>
<tr>
<td>Telefoonnr</td>
<td><span id="sprytextfield6"> <label for="Telefoonnr"></label> <input id="Telefoonnr" name="Telefoonnr" type="text" /> </span></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Email</td>
<td><span id="sprytextfield7"> <label for="Email"></label> <input id="Email" name="Email" type="text" /> </span></td>
<td> </td>
<td>Bijzonderheden</td>
<td><span id="sprytextarea1"> <label for="Bijzonderheden"></label> <textarea id="Bijzonderheden" cols="45" name="Bijzonderheden" rows="5"> </textarea> </span></td>
</tr>
<tr>
<td>Bank/gironr</td>
<td><span id="sprytextfield8"> <label for="Bankgiro"></label> <input id="Bankgiro" name="Bankgiro" type="text" /> </span></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="4"><br /><span id="sprycheckbox1"> <input id="Algemene Voorwaarden" name="Algemene Voorwaarden" type="checkbox" /> </span>Ik heb de de <strong>algemene voorwaarden</strong> gelezen en ga hiermee akkoord</td>
</tr>
<tr>
<td> </td>
<td><input id="Verzenden" name="Verzenden" type="submit" value="Verzenden" /></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</form>
Here is the mailsend.php:
<?php
require('class.mailer.info.php');
//phpinfo();
/* Vaste post waarden vastleggen */
// ontvanger
if(empty($_POST['redirect']))
{
die("error: geen ontvanger vastgelegd en redirect pad.");
}
// Instantiate your new class
$mail = new HeartmedicalMailer;
/*
Verwerken post informatie
*/
$body_text = '';
// waardes die je niet wilt tonen wegfilteren als redirect / receipient etc.
$excluded = array('redirect');
// html opmaak formulier voor loop
$body_text .= "<style>body{ font-family:Verdana, Arial; font-size:11px; color:#000000; }</style>";
// loop doorlopen met opmaak
foreach($_POST as $key => $value)
{
// vaste waardes wegfilteren
if(!in_array($key, $excluded))
{
if(!empty($value))
{
$key = preg_replace('#_#',' ', $key);
$body_text .= '<strong>'.$key.'</strong>: '.$value.'<br>';
}
}
}
// Now you only need to add the necessary stuff
$mail->Body = $body_text;
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
die("There was an error sending the message #code1");
}
// redirect
header("Location: ".$_POST['redirect']." ");
?>
Here is the class.mailer.info.php:
<?php
// class phpmailer
require("../phpmailer/class.phpmailer.php");
class HeartmedicalMailer extends PHPMailer
{
// Set default variables for all new objects
var $From = "xxxxx#xxxxx.nl";
var $FromName = "De Zwemschool";
var $Host = "localhost";
/* smtp auth */
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $SMTPAuth = false; // turn on SMTP authentication
var $Username = ""; // SMTP username
var $Password = ""; // SMTP password
var $WordWrap = 75;
var $Subject = "Inschrijving De Zwemschool";
function HeartmedicalMailer()
{
$this->AddAddress('xxxx#xxxx.nl', 'Name');
$this->IsHTML(true);
}
// Replace the default error_handler
function error_handler($msg) {
print("Mailer Error");
print("Description:");
printf("%s", $msg);
exit;
}
}
?>
I would like the form to be sent with recaptcha
You could use Google reCAPTCHA.
I personally use the reCAPTACHA V2 invisible one so you'll find an example below.
First get the keys here: link
Then replace your submit input with this:
<button class="g-recaptcha form-control" data-sitekey="YOUR_RECAPTCHA_KEY" data-callback='onSubmit'>Send</button>
Then add these scripts to your HTML page:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("form1").submit();
}
</script>
And finally add this at the begining of your mailsend.php:
function get_ip() {
// IP if shared network
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
// IP behind proxy
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
// Sinon : normal IP
else {
return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
}
}
// Anti spam using google Captcha
$post_params = [
'secret' => "YOUR",
'response' => $_POST['g-recaptcha-response'],
'remoteip' => get_ip()
];
# Create a connection
$url = 'https://www.google.com/recaptcha/api/siteverify';
$ch = curl_init($url);
# Form data string
$post_string = http_build_query($post_params, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
$response = json_decode($response);
curl_close($ch);
if(!$response->success){
exit();
}
Hope it helps ;)

How to send this with php mail function

I would like all additional input of benodigheden and ingrediënten are also sent. However, I do not know how you could pick up the cost of additional input. I hope somebody can help me.
This is my code
<div id="versturen">
<?php
if(isset ($_POST['Verzenden']))
{
$name = $_POST['Naam'];
$Email = $_POST['Email'];
$opmerking = $_POST ['Opmerking'];
$seizoen = $_POST ['Seizoen'];
/*-------------------------------------------------------------------------------------*/
/*---benodigheden---begin---*/
$benodigheden1 = $_POST ['benodigheden1'];
/*---benodigheden---eind---*/
/*---ingrediënten---begin---*/
$ingrediënten1 = $_POST ['ingrediënten1'];
/*---ingrediënten---eind---*/
$stappenplan = $_POST['stappenplan'];
/*-------------------------------------------------------------------------------------*/
$opmerking = $_POST ['Opmerking'];
/*-------------------------------------------------------------------------------------*/
$subject = 'GERECHT INDIENEN' . $seizoen . '' ;
$to = 'wross#live.nl, wvanhees35#hotmail.com';
$gerecht = 'BENODIGHEDEN <br />' . $benodigheden1 . '<br /> NGREDIËNTEN <br />' . $ingrediënten1 . '<br /> STAPPENPLAN <br />'. $stappenplan . '<br />';
$message = ''.$gerecht . $opmerking . ' Dit gerecht is ingestuurd door ' . $name . ' en is ingediend via ' .$Email;
mail($to, $subject, $message, "From:" . $Email)
?>
<div id="testing"><br /><h2>Uw mail is verzonden</h2></div>
<?php
header("Refresh: 3; URL=../index.php");
}
else{
?>
<form action="" method="post">
<legend>Neem contact op</legend>
<table>
<tr>
<td>
<label for="Naam">Naam: </label>
</td>
<td>
<input type="text" id="Naam" name="Naam" placeholder="Naam" required="required" />
</td>
</tr>
<tr>
<td>
<label for="Email">Email :</label>
</td>
<td>
<input type="email" id="Email"name="Email" placeholder="Email" required="required" />
</td>
</tr>
<tr>
<td>
<label for="Seizoen">Seizoen: </label>
</td>
<td>
<select name="Seizoen" id="Seizoen" required>
<option value="">Kies hier je seizoen</option>
<option value="Lente">Lente</option>
<option value="Zomer">Zomer</option>
<option value="Herfst">Herfst</option>
<option value="Winter">Winter</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<label for="benodigheden1">Benodigheden:</label>
</td>
<td>
<input type="text" id="benodigheden1"name="benodigheden1" placeholder="Benodigheden" required="required" />
</td>
</tr>
<tr>
<td>
<label for="ingrediënten1">Ingrediënten:</label>
</td>
<td>
<input type="text" id="ingrediënten1"name="ingrediënten1" placeholder="Ingrediënten" required="required" />
</td>
</tr>
<tr>
<td>
<label for="stappenplan">Stappenplanm:</label>
</td>
<td>
<textarea name="stappenplan" id="stappenplan" cols="40" rows="5" placeholder="Stappenplan" required="required" /></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<label for="Opmerking">Opmerking:</label>
</td>
<td>
<textarea name="Opmerking" id="Opmerking" cols="40" rows="5" placeholder="Opmerking" required="required" /></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div class="submit"><input type="submit" value="Verzenden" name="Verzenden" /></div>
</td>
</tr>
</table>
</form>
<?php
};
?>
</div>
Here is a link to JSFiddle.
He does not address here all my code (just as here).
Name the original and newly spawned input fields ingredienten[] and benodigheden[]
this will make them come in as a array in php.
foreach($_POST['benodigheden'] as $value){
echo $value .'<br />';
}
offcourse you need to change it to something usefull
I made a example see jsfiddle here place the above php somewhere and see wat happens if you submit
changed the html form input fields
<input type="text" id="benodigheden1"name="benodigheden[]" placeholder="Benodigheden" required="required" />
<input type="text" id="ingrediënten1"name="ingrediënten[]" placeholder="Ingrediënten" required="required" />
changed the javascript by adding this line " .attr('name',res[0]+'[]') "
// Add a line, and make it non-mandatory
$(this).clone()
.attr('id', newId).removeAttr('required')
.attr('name',res[0]+'[]')
.val('')
.insertAfter(this)
.before($('<br>'));

Create barcode reader using AJAX in PHP

I'm trying to build an application using php. in "stock_out.php", i wanna create a form that include two barcodes. I have 8 fields. (1)Effectivedate,(2)Partnumber,(3)Description1,(4)Description2,(5)NPK,(6)Nama,(7)QtyOut,(8)Reason. I wanna using barcode-reader in "Partnumber" and "NPK".
I have some problems:
1. When i press enter, it's respon for button submit.
2. Actually, when i press enter in Partnumber, i want show details data in "description1" and "description2". As well as in NPK, i want show details data in "nama"
3. In the end of form, i still want to submit this form into database.
I'm newbie in AJAX, so i still don't know how to implementation AJAX in PHP. This is my code, I am grateful for the help
<html><body>
<div id="outerContainer">
<?php include("headerFile.html"); ?>
<?php include("navigationFile.html"); ?>
<div id="bodyContainer">
<div id="pageBodyTitle"> Stock Out </div> <br>
<form id="formSearch" name="formSearch" method="post" action="proses_out.php" onSubmit="return cek_data();">
<table id="messageTable">
<tr>
<td class="heading"> Effective Date </td>
<td>
<input class="inputField" name="tgl" type="text" readonly value="<?php echo $_POST['tgl']?>" tabindex="1"/>
<script language='JavaScript'>new tcal ({'formname': 'formSearch','controlname': 'tgl'});</script>
</td>
</tr>
<tr>
<td class="heading"> Part Number </td>
<td><input type='text' name='txtItem' id='txtItem' size="20" class="inputField" value='<?php echo $item;?>' tabindex="2" />
<img src='search.ico' onClick='open_win_item()'> </td>
</tr>
<tr>
<td class="heading">Description1</td>
<td><input type='text' name='txtDesc1' id='txtDesc1' size="50" value='<?php echo $desc1;?>' readonly /></td>
</tr>
<tr>
<td class="heading">Description2</td>
<td><input type='text' name='txtDesc2' id='txtDesc2' size="50" value='<?php echo $desc2;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> NPK </td>
<td><input type='text' name='txtNpk' id='txtNpk' size="20" maxlength="5" class="inputField" value='<?php echo $tr_no;?>' tabindex="3" />
<img src='search.ico' onClick='open_win_npk()'></td>
</tr>
<tr>
<td class="heading">Nama</td>
<td><input type='text' name='txtName' id='txtName' size="30" value='<?php echo $nama;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> Qty Out </td>
<td><input type='text' name='txtQty' id='txtQty' size="5" class="inputField" tabindex="4"/></td>
</tr>
<tr>
<td class="heading"> Reason </td>
<td><select class="inputField" name="choose" id="choose" value="" tabindex="5">
<?php
include "/class/connect_SQL.class.php";
$sql = "select reason_code from Inv_reason_master";
$query = mssql_query($sql);
while ($row = mssql_fetch_array($query))
{
$coba = $row['reason_code'];
?>
<option value="<?php echo $coba; ?>"><?php echo $coba;?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Save" class="formButton2" tabindex="6"/>
<input type="reset" name="reset" value="Cancel" class="formButton2" tabindex="7"/>
</td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_GET["message"]) and $_GET["message"]='save')
{
echo "<script language=\"javascript\"> alert('Data Tersimpan!') </script>";
}
?>
<?php include("footerFile.html"); ?>
</div>
You will have to prevent the response of the "Enter"-key. If you are using jquery in your project you can prevent it with this code:
$(function() {
$("form").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
});
To bind Enter key to "Part number" field instead you could try this:
$('#txtItem').keypress(function(e) {
if (e.keyCode == 13) {
alert('Enter is pressed in part number');
}
});

PHP and mySQL Invitation only registration

I am trying to implement an invitation only registration system for a small business website.Where the administrator can type in an employee's personal email and have a verification code sent to him/her.
When the employee clicks on the link in the email he will be redirected to the registration page. (used switch to determine what shows)
The thing is I made the registration page earlier on and I am having trouble implementing it to this invitation code. The invitation code uses "echo" to display text while the original registration page has a form within a table created using php, html, and css. My question is how can I modify the code so that they are compatible.
Please see below for the code:
INVITE.php
mysql_select_db($database_connSQL, $connSQL);
$query_RecInvite = "SELECT * FROM invite_codes";
$RecInvite = mysql_query($query_RecInvite, $connSQL) or die(mysql_error());
$row_RecInvite = mysql_fetch_assoc($RecInvite);
$totalRows_RecInvite = mysql_num_rows($RecInvite);
/*
This script assumes you already have a database setup, with a connection string in place.
First, we'll need to create our table...
Copy/paste the following SQL code into the database you'll be using.
CREATE TABLE `invite_codes` (
`id` int(11) NOT NULL auto_increment,
`invite_code` varchar(35) NOT NULL default '',
`time_stored` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;
*/
function genRandomString($length) {
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
for ($p = 0; $p < $length; $p++) {
$string .= $chars[mt_rand(0, strlen($chars))];
}
return $string;
}
function clean($str) {
$value = mysql_escape_string(stripslashes(htmlspecialchars($str)));
return $value;
}
function sendEmail($mailto,$mailsubject,$mailcontent,$mailfrom) {
if($mailto == '' || $mailsubject == '' || $mailcontent == '' || $mailfrom == '') {
return false;
} else {
$headers = 'From: '.$mailfrom."\r\n".
'Reply-To: '.$mailfrom."\r\n" .
'X-Mailer: PHP/'.phpversion();
if(mail($mailto, $mailsubject, $mailcontent, $headers)) {
return true;
} else {
return false;
}
}
}
function checkEmail($email) {
if(!ereg("^[^#]{1,64}#[^#]{1,255}$", $email)) { return false; }
$email_array = explode("#", $email);
$local_array = explode(".", $email_array[0]);
for($i = 0; $i < sizeof($local_array); $i++) {
if(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if(!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) { return false; }
for($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
(empty($_GET['go']))?($go = 'home'):($go = $_GET['go']);
switch($go) {
case 'home':
echo 'This is an invite code example..<br />Generate a new invite code:<br />
<form action="?go=generate" method="post">
<input name="submit" type="submit" value="Generate" />
</form>';
break;
case 'generate':
$invite_code = genRandomString(25); // genRandomString( INT )
echo 'This is a random invite code: <b>'.$invite_code.'</b><br />Let's go ahead and toss this into our database...';
if(mysql_query("INSERT INTO invite_codes (id,invite_code,time_stored) VALUES ('','".$invite_code."','".mktime()."')")) {
echo '<br />Insertion successful<br /><br />Use code to invite a friend:<br />';
echo '<p><form action="?go=invite" method="post">
<input type="text" name="email" id="email" value="" />
<input type="hidden" name="code" id="code" value="'.$invite_code.'" />
<input name="submit" type="submit" value="Invite" />
</form></p>';
} else { echo 'Whoops! Something went horribly wrong, and we couldn't store the code :('; }
break;
case 'invite':
if(!empty($_POST['email'])) {
if(checkEmail($_POST['email'])) {
$thisDomain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mailcont = "Someone has invited you to an invite only website!\nYour invite code is: ".$_POST['code'].".\n\nYou can use it at http://www.".$thisDomain."/newTATCS/login/invite.php?go=register&hash=".$_POST['code'];
if(sendEmail($_POST['email'],'You have been invited!',$mailcont,'noreply#'.$thisDomain)) {
echo 'Your invite was dispatched to '.$_POST['email'].'<br /><br />Go back home';
} else { echo 'Whoops! Something went horribly wrong, and we couldn't send the email :('; }
} else { 'Whoops! Looks like the email address you selected is invalid :('; }
} else { 'Whoops! It looks like you didn't actually add an email address...'; }
break;
case 'register':
if(!empty($_POST['code'])) {
$code = clean($_POST['code']); // Because SQL injections are annoying :)
$query = mysql_query("SELECT id FROM invite_codes WHERE invite_code = '".$code."'");
if(mysql_num_rows($query) == 1) {
$fetch = mysql_fetch_object($query);
echo 'Congratulations, the invite code was found!<br />We're going to remove it from the database now...';
if(mysql_query("DELETE FROM invite_codes WHERE id = '".$fetch->id."'")) {
echo '<br />Code removed!';
} else { echo 'Whoops! Something went horribly wrong, and we couldn't remove the code :('; }
} else { echo 'Sorry, that code is invalid.'; }
} else {
echo 'This website is closed to the public. You will need an invite code to continue registration.
<p><form action="?go=register" method="post">
<input type="text" name="code" id="code" value="'.$_GET['hash'].'" />
<input name="submit" type="submit" value="Check" />
</form></p>';
}
break;
}
?>
REGISTER.php
<form id="register" name="register" method="POST" action="<?php echo $editFormAction; ?><?php echo $loginFormAction; ?>">
<div class="leftRegister">
<table width="278" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="278">Saultation<br />
<select name="salutation" id="salutation">
<option selected="selected">Mr.</option>
<option>Mrs.</option>
<option>Ms.</option>
<option>Dr.</option>
<option>Prof.</option>
</select></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="278" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="138">Name<br /></td>
<td width="140"> </td>
</tr>
<tr>
<td valign="top"><span id="sprytextfield1">
<input name="firstname" class="regFirstname" type="text" id="firstname" />
<br />
<span class="textfieldRequiredMsg">Enter your First name .</span></span></td>
<td width="140" valign="top"><span id="sprytextfield2">
<input type="text" class="regLastname" name="lastname" id="lastname" />
<br />
<span class="textfieldRequiredMsg">Enter your Last name.</span></span></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Personal Email<br />
<span id="sprytextfield9">
<input type="text" name="email" id="email" />
<br />
<span class="textfieldRequiredMsg">Please enter your personal email.</span></span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Create a password<br />
<span id="sprypassword1">
<input type="password" name="password" id="password" />
<br />
<span class="passwordRequiredMsg">Please choose a password that contain at least<br />
1 letter and 1 number for maximum security.</span><span class="passwordMinCharsMsg">Minimum number of characters not met.<br />
Password must contain at least 5 characters.</span><span class="passwordInvalidStrengthMsg">Password must contain at least 1 letter and 1 number.</span></span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Confirm your password<br />
<span id="spryconfirm1">
<input type="password" name="passwordcheck" id="passwordcheck" />
<span class="confirmRequiredMsg"><br />
Please make sure your password matches</span><span class="confirmInvalidMsg"><br />
The values don't match.</span></span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Birthday<br />
<select name="BirthMonth">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="BirthDay">
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="BirthYear">
<?php
for ($i=2006; $i>=1900; $i=$i-1)
{
echo "<option value='$i'>$i</option>";
}
?>
</select></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</div>
<div class ="rightRegister">
<table width="280" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">Address
<br />
<span id="sprytextfield3">
<input type="text" name="address" id="address" />
<br />
<span class="textfieldRequiredMsg">Please enter your address</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">City<br />
<span id="sprytextfield4">
<input type="text" name="city" id="city" />
<br />
<span class="textfieldRequiredMsg">Please enter your city.</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="108" valign="top">State/Province<br />
<span id="sprytextfield5">
<input type="text" name="state" id="state" class="regState" />
<span class="textfieldRequiredMsg">State required.</span></span></td>
<td width="144" valign="top">Zip/Postal Code<br />
<span id="sprytextfield6">
<input type="text" name="postalcode" id="postalcode" class="regPostalcode" />
<span class="textfieldRequiredMsg"><br />
Zip Code required.</span><span class="textfieldMaxCharsMsg"><br />
Enter 5-digit Zip code.</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Homephone
<span id="sprytextfield7"><br />
<input type="text" name="homephone" id="homephone" />
<br />
<span class="textfieldRequiredMsg">Please enter phone number.</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Cellphone<br />
<span id="sprytextfield8">
<input type="text" name="cellphone" id="cellphone" />
<br />
<span class="textfieldRequiredMsg">Please enter your cellphone number.</span></span></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="right"><span class="submit">
<input type="submit" value="Submit" />
</span></td>
</tr>
<tr>
<td colspan="2" align="right"> </td>
</tr>
</table>
<p> </p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<input type="hidden" name="MM_insert" value="register" />
</form>
</div>
On your registration page, pull the invitation code from the query string (site.php?code=ajiofdjasoiej39048). Then, check if a row exists in the database with that invitation code. If it does, then display the registration form. Otherwise display an error message. Check the code again on submission, and after the user is registered successfully, delete the invite code from the DB.
Also, php_mysql is deprecated. Please use MySQLi or PDO instead.

Pass multiple checkboxes and file upload using jQuery ajax to php to email

I am trying to pass the checkboxes value to email and have an uploaded file add as attachment on the email. Here is what I have so far (everything works, but the checkbox being passed and the file upload)... The main thing I need is the checkboxes - file upload is just a extra - also how would you send this to a database too ;]
HTML Form:
<form id="reg-form" class="cols" method="post" action="#">
<fieldset class="w50">
<p class="form-subscr-field">
<label for="reg_first" id="reg_first_label">First Name: <span style="color:#F00">*</span></label>
<input id="reg_first" type="text" name="reg_first" class="inputbox" size="10" tabindex="1" />
<label class="error error-tip" for="reg_first" id="first_error" style="display: none;">Please enter your First Name</label>
</p>
<p class="form-subscr-field">
<label for="reg_email" id="reg_email_label">E-mail Address: <span style="color:#F00">*</span></label>
<input id="reg_email" type="text" name="reg_email" class="inputbox" size="10" tabindex="3" />
<label class="error error-tip" for="reg_email" id="email_error" style="display: none;">Please enter your Email Address</label>
<label class="error error-tip" for="reg_email" id="invalid_error" style="display: none;">Invalid Email Address.</label>
</p>
<p class="form-subscr-field">
<label for="reg_zip" id="reg_zip_label">Zip Code: <span style="color:#F00">*</span></label>
<input id="reg_zip" type="text" name="reg_zip" class="inputbox" size="10" tabindex="5" />
<label class="error error-tip" for="reg_zip" id="zip_error" style="display: none;">Please enter your Zip Code</label>
<label class="error error-tip" for="reg_zip" id="invalid_error2" style="display: none;">Invalid Zip Code.</label>
</p>
<p class="form-subscr-field">
<label for="reg_company" id="reg_company_label">Company Name: </label>
<input id="reg_company" type="text" name="reg_company" class="inputbox" size="10" tabindex="1" />
</p>
</fieldset>
<fieldset class="w50">
<p class="form-subscr-field">
<label for="reg_last" id="reg_last_label">Last Name: <span style="color:#F00">*</span></label>
<input id="reg_last" type="text" name="reg_last" class="inputbox" size="10" tabindex="2" />
<label class="error error-tip" for="reg_last" id="last_error" style="display: none; width:200px;">Please enter your Last Name</label>
</p>
<p class="form-subscr-field">
<label for="reg_phone" id="reg_phone_label">Phone Number: <span style="color:#F00">*</span></label>
<input id="reg_phone" type="text" name="reg_phone" class="inputbox" size="10" maxlength="20" tabindex="4" />
<label class="error error-tip" for="reg_phone" id="phone_error" style="display: none; width:200px;">Please enter your Phone Number</label>
</p>
<p class="form-subscr-field">
<label for="reg_areyou" id="reg_areyou_label">Are you…</label>
<select id="reg_areyou" type="text" name="reg_areyou" class="inputbox" tabindex="6">
<option value="Opt1">Select an option</option>
<option value="Homeowner">Homeowner</option>
<option value="Contractor">Contractor</option>
<option value="Commercial Buyer">Commercial Buyer</option>
<option value="Other">Other</option>
</select>
</p>
<p class="form-subscr-field">
<label for="reg_upload" id="reg_upload_label">Do you have a detailed file or image for your project - Upload it now! </label>
<input name="reg_upload" id="reg_upload" type="file" style="cursor:pointer;">
</p>
</fieldset>
<div class="clear"></div><br/>
<h3 class="underline"><strong>Project</strong> Information</h3>
<label>Are you looking into doing any of the following?</label>
<table cellpadding="5" cellspacing="5" border="1" width="100%">
<tr>
<td align="left" valign="top"><input name="reg_checkPick" id="Decking" value="Decking" type="checkbox"><label>Decking</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Windows" value="Windows" type="checkbox"><label>Windows</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Doors" value="Doors" type="checkbox"><label>Doors</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Flooring" value="Flooring" type="checkbox"><label>Flooring</label></td>
</tr>
<tr>
<td align="left" valign="top"><input name="reg_checkPick" id="Countertops" value="Countertops" type="checkbox"><label>Countertops</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Cabinets" value="Cabinets" type="checkbox"><label>Cabinets</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Sink and Faucets" value="Sink and Faucets" type="checkbox"><label>Sink and Faucets</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Siding" value="Siding" type="checkbox"><label>Siding</label></td>
</tr>
<tr>
<td align="left" valign="top"><input name="reg_checkPick" id="Roofing" value="Roofing" type="checkbox"><label>Roofing</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Paint" value="Paint" type="checkbox"><label>Paint</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Hardware" value="Hardware" type="checkbox"><label>Hardware</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Fireplaces" value="Fireplaces" type="checkbox"><label>Fireplaces</label></td>
</tr>
<tr>
<td align="left" valign="top"><input name="reg_checkPick" id="Installation" value="Installation" type="checkbox"><label>Installation</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Design Ideas" value="Design Ideas" type="checkbox"><label>Design Ideas</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Furnishings" value="Furnishings" type="checkbox"><label>Furnishings</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Plumbing" value="Plumbing" type="checkbox"><label>Plumbing</label></td>
</tr>
<tr>
<td align="left" valign="top"><input name="reg_checkPick" id="Lumber" value="Lumber" type="checkbox"><label>Lumber</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Specialty Rooms" value="Specialty Rooms" type="checkbox"><label>Specialty Rooms</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Trusses" value="Trusses" type="checkbox"><label>Trusses</label></td>
<td align="left" valign="top"><input name="reg_checkPick" id="Mill Work" value="Mill Work" type="checkbox"><label>Mill Work</label></td>
</tr>
</table>
<p class="form-subscr-field">
<label for="reg_message" id="comment_label">Project Details: <span style="color:#F00">*</span></label>
<textarea id="reg_message" name="reg_message" rows="8" cols="30" tabindex="8" placeholder="Please provide as much information and details that you can."></textarea>
<label class="error error-tip" for="reg_message" id="message_error" style="display: none;">Please enter Your Message</label>
</p>
<p class="form-subscr-field">
<label for="reg_human" id="reg_human_label">Please add <strong>2 + 2</strong> to verify your human! <span style="color:#F00">*</span></label>
<input id="reg_human" type="text" name="reg_human" class="inputbox" maxlength="1" size="1" placeholder="Hint - it's 4" tabindex="9" />
<label class="error error-tip" for="reg_human" id="human_error" style="display: none;">You need to enter 4.</label>
<label class="error error-tip" for="reg_human" id="invalid_error3" style="display: none;">Your math is off.</label>
</p>
<div class="clear"></div>
<div class="submit-contact">
<p><input type="submit" class="cool-button2 csbutton spot-action" value="Submit" tabindex="10" /> <button type="reset" class="csbutton-color" tabindex="11">Reset</button></p>
</div>
</form>
JS File
//quote form validation
$(function () {$('.error').hide(); $(".cool-button2").click(function () {$('.error').hide(); $("label#invalid_error").hide(); $("label#email_error").hide();
var first2 = $("input#reg_first").val(); if (first2 === "") {$("label#first_error").show(); $("input#reg_first").focus(); return false; }
var last2 = $("input#reg_last").val(); if (last2 === "") {$("label#last_error").show(); $("input#reg_last").focus(); return false; }
var email2 = $("input#reg_email").val(); if (email2 === "") {$("label#email_error").show(); $("input#reg_email").focus(); return false; }
var emailRegEx2 = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*#(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
var phone2 = $("input#reg_phone").val(); if (phone2 === "") {$("label#phone_error").show(); $("input#reg_phone").focus(); return false; }
var zip2 = $("input#reg_zip").val(); if (zip2 === "") {$("label#zip_error").show(); $("input#reg_zip").focus(); return false; }
var zipRegEx2 = /^\d{5}(-\d{4})?$/;
var areyou2 = $('#reg_areyou option:selected').text();
var company2 = $("input#reg_company").val();
var checkboxValues = new Array(); $("input[name='reg_checkPick']:checked").each(function(i) {data.push($(this).val());});
var message2 = $("textarea#reg_message").val(); if (message2 === "") {$("label#message_error").show(); $("textarea#reg_message").focus(); return false; }
var human2 = $("input#reg_human").val(); if (human2 === "") {$("label#human_error").show(); $("input#reg_human").focus(); return false; }
var humanRegEx2 = 4;
if (document.getElementById('reg_email').value.search(emailRegEx2) === -1) { $("label#invalid_error").show(); $("input#reg_email").focus(); }
else if (document.getElementById('reg_zip').value.search(zipRegEx2) === -1) { $("label#invalid_error2").show(); $("input#reg_zip").focus(); }
else if (document.getElementById('reg_human').value.search(humanRegEx2) === -1) { $("label#invalid_error3").show(); $("input#reg_human").focus(); }
else {
var dataString = 'reg_first=' + first2 + '&reg_last=' + last2 + '&reg_email=' + email2 + '&reg_phone=' + phone2 + '&reg_zip=' + zip2 + '&reg_areyou=' + areyou2 + '&reg_company=' + company2 + '&reg_checkPick=' + checkboxValues + '&reg_message=' + message2; $.ajax({type: "POST", url: "reg.php", data: dataString, success: function () {$('#reg-form').html("<div id='message2'></div>"); $('#message2').html("<h3>Request Submitted</h3>").append("<p>Thank you for contacting us - we will be in touch. If you have any further questions, you can always mail us at notmine or call our support team at Ph: 00000000.</p>").hide().fadeIn(1500, function () {$('#message2').append("<img id='checkmark' src='/submit.png' />"); }); }}); }
return false; }); });
PHP File:
<?php
if ((isset($_POST['reg_first'])) && (strlen(trim($_POST['reg_first'])) > 0)) {
$reg_first = stripslashes(strip_tags($_POST['reg_first']));
} else {$reg_first = 'No First Name entered';}
if ((isset($_POST['reg_last'])) && (strlen(trim($_POST['reg_last'])) > 0)) {
$reg_last = stripslashes(strip_tags($_POST['reg_last']));
} else {$reg_last = 'No Last Name entered';}
if ((isset($_POST['reg_email'])) && (strlen(trim($_POST['reg_email'])) > 0)) {
$reg_email = stripslashes(strip_tags($_POST['reg_email']));
} else {$reg_email = 'No email entered';}
if ((isset($_POST['reg_phone'])) && (strlen(trim($_POST['reg_phone'])) > 0)) {
$reg_phone = stripslashes(strip_tags($_POST['reg_phone']));
} else {$reg_phone = 'No Phone Number entered';}
if ((isset($_POST['reg_areyou'])) && (strlen(trim($_POST['reg_areyou'])) > 0)) {
$reg_areyou = stripslashes(strip_tags($_POST['reg_areyou']));
} else {$reg_areyou = 'No selection';}
if ((isset($_POST['reg_zip'])) && (strlen(trim($_POST['reg_zip'])) > 0)) {
$reg_zip = stripslashes(strip_tags($_POST['reg_zip']));
} else {$reg_zip = 'No Zip Code entered';}
if ((isset($_POST['reg_company'])) && (strlen(trim($_POST['reg_company'])) > 0)) {
$reg_company = stripslashes(strip_tags($_POST['reg_company']));
} else {$reg_company = 'No Company Name entered';}
if ((isset($_POST['reg_checkPick'])) && (strlen(trim($_POST['reg_checkPick'])) > 0)) {
$reg_checkPick = stripslashes(strip_tags($_POST['reg_checkPick']));
} else {$reg_checkPick = 'Noting was checked';}
if ((isset($_POST['reg_message'])) && (strlen(trim($_POST['reg_message'])) > 0)) {
$reg_message = stripslashes(strip_tags($_POST['reg_message']));
} else {$reg_message = 'No message entered';}
ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<table width="600" border="1" cellspacing="2" cellpadding="2">
<tr bgcolor="#eeffee">
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Phone Number</td>
<td>Zip Code</td>
<td>Are You</td>
<td>Company Name</td>
<td>Looking into doing the following</td>
<td>Message</td>
</tr>
<tr bgcolor="#eeeeff">
<td><?=$reg_first;?></td>
<td><?=$reg_last;?></td>
<td><?=$reg_email;?></td>
<td><?=$reg_phone;?></td>
<td><?=$reg_zip;?></td>
<td><?=$reg_areyou;?></td>
<td><?=$reg_company;?></td>
<td><?=$reg_checkPick;?></td>
<td><?=$reg_message;?></td>
</tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();
$to = 'notmine#hotmail.com';
$email = $reg_email;
$fromaddress = $reg_email;
$fromname = "Request a Quote";
require("phpmailer.php");
$mail = new PHPMailer();
$mail->From = $reg_email;
$mail->FromName = ("$reg_first $reg_last");
$mail->AddAddress("notmine#hotmail.com","not mine"); //change to your email address
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Request a Quote: form submitted";
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
if(!$mail->Send()) {
$recipient = 'notmine#hotmail.com'; //change to your email address
$subject = 'reg Info Form: form failed';
$content = $body;
mail($recipient, $subject, $content, "From: $reg_email\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
?>
For getting checkbox value use
<input name="reg_checkPick[]" id="Countertops" value="Countertops" type="checkbox">
instead of
<input name="reg_checkPick" id="Countertops" value="Countertops" type="checkbox">
ie you have to specify name as an array.
And on submitting the checkbox value will be in an array and can take values using a loop or something.
I hope this will help you.
$(':checkbox').map(function() {
return this.id;
}).get().join(','); 
Once in my project i used the map like this:
I have changed so that you can use in your code First, make the table with id.
<table id='checkboxes' cellpadding='5' cellspacing='5' border='1' width='100%'>
In your js change the check box code .You can still take that exact [name='reg_checkPick']for below code to make it more specific.
I have tested in my local.
var selected = $("#checkboxes input:checked").map(function(i,el){
return $(this).val();}).get();
alert(selected);
you will get the values in alert as this
ex:if i have selected the Paint and Design ideas
Paint,Design Ideas

Categories