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.
Related
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>'));
I have created a form which takes the data and inserts it in the database. onlick of create button i want the function to check database whether the entry with employee_id already exists. if exists i want it to display the data already exists do you still want to insert, i am noob in this can anybody help me with this. the form is
<form id="myForm" name="myForm" action='insert.php' method='post' >
<input type='hidden' name='st' value=0>
<table style="text-align:center; width:100%">
<tr>
<td style="text-align:right"><label>Select SE/AE:</label></td>
<td style="text-align:left">
<?php include("configs.php");
$sql = "SELECT DISTINCT seae FROM se_ae ";?>
<select name="seae">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['seae']; ?>">
<?php echo $row['seae']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Brand:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `brand` FROM se_ae ";?>
<select name="brand">
<option value="" selected> </option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['brand']; ?>">
<?php echo $row['brand']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Territory:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `territory` FROM se_ae ";?>
<select name="territory">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['territory']; ?>">
<?php echo $row['territory']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="name">Employee Name:</label></td>
<td style="text-align:left">
<input type="text" id="name" name="name"/>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="number">Employee ID:</label></td>
<td style="text-align:left">
<input type="text" id="number" name="number" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="email"> Email:</label></td>
<td style="text-align:left">
<input type="text" id="email" name="email" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="contact"> Contact:</label></td>
<td style="text-align:left">
<input type="text" id="contact" name="contact" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="exist"> Exist:</label></td>
<td style="text-align:left">
<input type="radio" id="exist" name="exist" value="Active"/>Active
<input type="radio" id="exist" name="exist" value="NA"/>NA
</td>
</tr>
<tr>
<td style="text-align:right" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="Reset" type="reset" value="Reset">
</td>
<td style="text-align:left" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="submit" type="submit" value="Create">
</td>
</tr>
</table>
</form>
You can use the Jquery validation
$(function () {
$("#resturantRegistration").validate({
rules: {
number: {
required: true,
remote:"user/checkEmployee"
}
},
messages: {
number: {
required: "Please enter Employee id",
remote: $.validator.format("Employee id already in use")
}
}
});
});
PHP function
function checkEmployee(){
$emailid = $_GET['number'];
if(!empty($emailid)){
$emailRes = $this->users->is_email_available($emailid);
if ($emailRes == ''){
echo 'false';
} else {
echo 'true';
}
}
}
Model function to check with database
/**
* Check if email available for registering
*
* #param string
* #return bool
*/
function is_email_available($email)
{
$this->db->select('1', FALSE);
$this->db->where('LOWER(email)=', strtolower($email));
$this->db->or_where('LOWER(new_email)=', strtolower($email));
$query = $this->db->get($this->table_name);
return $query->num_rows() == 0;
}
above code is follow the codeigniter MVC framework you can customize this in core PHP as well
I am having concern re this input type FILE I used for uploading an image. In an edit state, every time the user enters the edit form, the input type file for the image becomes null. Its not like every time the user edits, he/she would want to edit his/her picture, too. I am trying to apply value="<?php echo $fuser['file'] ?>" just like what i did with the input type TEXT, but i have learned that putting value for an input type file is just a waste. How would I get the value of the last chosen image so that when a user does not want to edit the picture, the image still remains.
Here is my code:
<?php session_start(); ?>
<?php if($_SESSION["schoUsername"]) { ?>
<?php
include('konek.php');
$user=mysql_query("select * from tblscholar where id='$_REQUEST[edit_id]'");
$fuser=mysql_fetch_array($user);
if(isset($_POST['UPDATE']) && $_POST['UPDATE']=='Update')
{
$id=$_POST['id'];
$schoSurname=$_POST['schoSurname'];
$schoFirstname=$_POST['schoFirstname'];
$schoMiddlename=$_POST['schoMiddlename'];
$schoCourse=$_POST['schoCourse'];
$schoSchool=$_POST['schoSchool'];
$schoSag=$_POST['schoSag'];
$schoPosition=$_POST['schoPosition'];
$schoUsername=$_POST['schoUsername'];
$schoPassword=$_POST['schoPassword'];
$schoEmail=$_POST['schoEmail'];
$file=$_FILES['file']['name'];
$error=array("schoSurname"=>"","schoFirstname"=>"","schoMiddlename"=>"","schoCourse"=>"","schoSchool"=>"","schoSag"=>"","schoPosition"=>"","schoUsername"=>"","schoPassword"=>"","schoEmail"=>"","file"=>"");
//********************schoSurname*********************
if($schoSurname=="")
{
$error['schoSurname']="Lastname Is Required.";
}
else
{
if(!preg_match('/^[a-zA-Z\s]+$/',$schoSurname))
{
$error['schoSurname']="Lastname Can't Contain Numeric Value.";
}
else
{
$valid_lastname=$schoSurname;
}
}
//********************schoFirstname*********************
if($schoFirstname=="")
{
$error['schoFirstname']="Firstname Is Required.";
}
else
{
if(!preg_match('/^[a-zA-Z\s]+$/',$schoFirstname))
{
$error['schoFirstname']="Firstname Can't Contain Numeric Value.";
}
else
{
$valid_firstname=$schoFirstname;
}
}
//********************schoMiddlename*********************
if($schoMiddlename=="")
{
$error['schoMiddlename']="Middlename Is Required.";
}
else
{
if(!preg_match('/^[a-zA-Z\s]+$/',$schoMiddlename))
{
$error['schoMiddlename']="Middlename Can't Contain Numeric Value.";
}
else
{
$valid_middlename=$schoMiddlename;
}
}
//********************schoCourse*********************
if($schoCourse=="")
{
$error['schoCourse']="Course Is Required.";
}
else
{
if(!preg_match('/^[a-zA-Z\s]+$/',$schoCourse))
{
$error['schoCourse']="Course Can't Contain Numeric Value.";
}
else
{
$valid_course=$schoCourse;
}
}
//********************schoSchool*********************
if($schoSchool=="")
{
$error['schoSchool']="School Is Required.";
}
else
{
if(!preg_match('/^[a-zA-Z\s]+$/',$schoSchool))
{
$error['schoSchool']="School Can't Contain Numeric Value.";
}
else
{
$valid_school=$schoSchool;
}
}
//********************schoEmail*********************
if($schoEmail=="")
{
$error['schoEmail']="Email Is Required.";
}
else
{
if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $schoEmail))
{
$valid_email=$schoEmail;
}
else
{
$error['schoEmail']="Invalid Email Address.";
}
}
//********************file*********************
if($file=="")
{
$error['file']="Image Is Required.";
}
else
{
if($_FILES['file']['type']=='image/jpeg' || $_FILES['file']['type']=='image/jpg')
{
$valid_file=$file;
}
else
{
$error['file']="Image Must Be .jpg or .jpeg";
}
}
if( (strlen($valid_lastname)>0) && (strlen($valid_firstname)>0) && (strlen($valid_middlename)>0) && (strlen($valid_course)>0) && (strlen($valid_school)>0) && (strlen($valid_email)>0) && (strlen($valid_file)>0))
{
$sel=mysql_query("SELECT * FROM tblscholar WHERE schoEmail='$schoEmail' id!=$_REQUEST[edit_id]");
$n=mysql_num_rows($sel);
if($n==0)
{
$path="scholarspics/";
copy($_FILES['file']['tmp_name'],$path.$file);
$upd="update tblscholar set schoSurname='$schoSurname',schoFirstname='$schoFirstname',schoMiddlename='$schoMiddlename',schoCourse='$schoCourse',schoSchool='$schoSchool',schoSag='$schoSag',schoPosition='$schoPosition',schoUsername='$schoUsername',schoPassword='$schoPassword',schoEmail='$schoEmail',file='$file' where id=$_REQUEST[edit_id]";
mysql_query($upd);
echo "<script>
alert('(Id No.$_REQUEST[edit_id]) Record Successfully Updated.');
window.location='Dashboard.php';
</script>";
}
else
{
$error['email'] = "Same Email Already Exist";
}
}
}
?><head>
<title> Edit Record </title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<?php include "header.php";?> </head>
<div id="divTitleHead">
<strong>EDIT SCHOLAR</strong>
</div>
<div id = "divInsertAnnouncement">
<div id="divInnerIA">
<form name="f1" method="post" enctype="multipart/form-data">
<table width="600px" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="70px">ID</td>
<td width="7px">:</td>
<td color="#0d192f"><b><?php echo $fuser['id']; ?></b></td>
</tr>
<tr>
<td>Lastname</td>
<td>*</td>
<td>
<input type="text" name="schoSurname" id="schoSurname" class="box" value="<?php echo $fuser['schoSurname']; ?>" />
<span class="err"><?php echo $error["schoSurname"];?></span>
</td>
</tr>
<tr>
<td>First Name</td>
<td>*</td>
<td>
<input type="text" name="schoFirstname" id="schoFirstname" class="box" value="<?php echo $fuser['schoFirstname']; ?>" />
<span class="err"><?php echo $error["schoFirstname"];?></span>
</td>
</tr>
<tr>
<td>Middle Name</td>
<td>*</td>
<td><input type="text" name="schoMiddlename" id="schoMiddlename" class="box" value="<?php echo $fuser['schoMiddlename']; ?>" />
<span class="err"><?php echo $error["schoMiddlename"];?></span></td>
</tr>
<tr>
<td>School</td>
<td>*</td>
<td><input type="text" name="schoSchool" id="schoSchool" class="box" value="<?php echo $fuser['schoSchool'];?>" />
<span class="err"><?php echo $error["schoSchool"];?></span></td>
</tr>
<tr>
<td>Course</td>
<td>*</td>
<td><input type="text" name="schoCourse" id="schoCourse" class="box" value="<?php echo $fuser['schoCourse'];?>" />
<span class="err"><?php echo $error["schoCourse"];?></span></td>
</tr>
<tr>
<td>SAG</td>
<td>*</td>
<td>
<select name="schoSag" id="schoSag" class="box">
<option value="Businesslicious" <?php if($fuser['schoSag']=='Businesslicious') echo "selected='selected'";?>>Businesslicious</option>
<option value="Engineering" <?php if($fuser['schoSag']=='Engineering') echo "selected='selected'";?>>Engineering Design</option>
<option value="Gods_Squad" <?php if($fuser['schoSag']=='Gods_Squad') echo "selected='selected'";?>>God's Squad</option>
<option value="Marketista" <?php if($fuser['schoSag']=='Marketista') echo "selected='selected'";?>>Marketista</option>
<option value="MDAS" <?php if($fuser['schoSag']=='MDAS') echo "selected='selected'";?>>MDAS</option>
<option value="Professional_Warriors">Professional Warriors</option>
<option value="Rhetor" <?php if($fuser['schoSag']=='Rhetor') echo "selected='selected'";?>>Rhetor</option>
<option value="Socialites" <?php if($fuser['schoSag']=='Socialites') echo "selected='selected'";?>>Socialites</option>
<option value="Techies" <?php if($fuser['schoSag']=='Techies') echo "selected='selected'";?>>Techies</option>
</select>
</td>
</tr>
<tr>
<td>Position</td>
<td>*</td>
<td>
<select name="schoPosition" id="schoPosition" class="box">
<option value="President" <?php if($fuser['schoPosition']=='President') echo "selected='selected'";?>>President</option>
<option value="Vice_President_Internal" <?php if($fuser['schoPosition']=='Vice_President_Internal') echo "selected='selected'";?>>Vice President Internal</option>
<option value="Vice_President_External" <?php if($fuser['schoPosition']=='Vice_President_External') echo "selected='selected'";?>>Vice President External</option>
<option value="Secretary_General" <?php if($fuser['schoPosition']=='Secretary_General') echo "selected='selected'";?>>Secretary General</option>
<option value="Assistant_Secretary"<?php if($fuser['schoPosition']=='Assistant_Secretary') echo "selected='selected'";?>>Assistant Secretary</option>
<option value="Finance_Committee_Head" <?php if($fuser['schoPosition']=='Finance_Committee_Head') echo "selected='selected'";?>>Finance Committee Head</option>
<option value="Legal_and_Corporate_Affairs_Committee_Head" <?php if($fuser['schoPosition']=='Legal_and_Corporate_Affairs_Committee_Head') echo "selected='selected'";?>>Legal and Corporate Affairs Committee Head</option>
<option value="Spiritual_and_Community_Services_Committee_Head" <?php if($fuser['schoPosition']=='Spiritual_and_Community_Services_Committee_Head') echo "selected='selected'";?>>Spiritual and Community Services Committee Head</option>
<option value="Librarian" <?php if($fuser['schoPosition']=='Librarian') echo "selected='selected'";?>>Librarian</option>
<option value="Member" <?php if($fuser['schoPosition']=='Member') echo "selected='selected'";?>>Member</option>
<option value="Leader" <?php if($fuser['schoPosition']=='Leader') echo "selected='selected'";?>>Leader</option>
</select>
</td>
</tr>
<tr>
<td>Username</td>
<td>*</td>
<td><input type="text" name="schoUsername" id="schoUsername" class="box" value="<?php echo $fuser['schoUsername'];?>" />
<span class="err"><?php echo $error["schoUsername"];?></span></td>
</tr>
<tr>
<td>Password</td>
<td>*</td>
<td><input type="text" name="schoPassword" id="schoPassword" class="box" value="<?php echo $fuser['schoPassword'];?>" />
<span class="err"><?php echo $error["schoPassword"];?></span></td>
</tr>
<tr>
<td>Email</td>
<td>*</td>
<td><input type="text" name="schoEmail" class="box" onblur="checkEmail('checkEmail.php?schoEmail='+this.value)" class="fieldsize" value="<?php echo $fuser['schoEmail']?>"/>
<span class="err" id="checkEmail"><?php echo $error["schoEmail"];?></span></td>
</tr>
<tr>
<td>Image</td>
<td>
<input type="file" name="file" /><br>
<img src="scholarspics/<?php echo $fuser[11]; ?>" height="150" width="150"/>
<span class="err"><?php echo $error["file"];?></span></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="button" value="Cancel" class="btn"onClick="alert('No Changes Have Been Made');window.location='viewscholars.php';" />
<input type="submit" name="UPDATE" value="Update" class="btn" /></td>
</tr>
</table>
</form>
</div>
</div>
<?php
}
?>
Hi,
I have a form and I want to insert its values into a MySQL database without refreshing the form and losing its values.
By clicking on the 'print' button the user should be able to generate a report from the data they entered in the form, but the form keeps refreshing on submit. So I would like to know how I can store the data in the database without having the form refreshed (i.e. using Ajax)?
Below is my form code:
<div class="commentpost"></div>
<form name="entry" id="entry" method="POST" action="">
<table border="1" bgcolor="Silver">
<tr>
<td>
</td>
<td>
<h2><b>Candidate Entry</b><h2>
</td>
</tr>
<tr>
<td>
Code
</td>
<td>
<input type="text" name="vouchno" value="New" onkeypress="return isNumberKey(event)" readonly="readonly" size="8" maxlength="8">
Date
<input type="text" id="vouchdt" name="vouchdt" id="popupDatepicker" tabindex="1" value="<?php echo (isset($_POST['vouchdt']) ? $_POST['vouchdt'] : ''); ?>"></td>
<td>
<input type="text" id='councode' name="councode" size="1" maxlength="2" value="<?php echo (isset($_POST['councode']) ? $_POST['councode'] : ''); ?>"><input type="text" id="counvouch" name="counvouch" size="8" value="<?php echo (isset($_POST['counvouch']) ? $_POST['counvouch'] : ''); ?>" maxlength="8">
<div id="cam">
</div>
<input type=button value="Configure..." onClick="webcam.configure()">
<input type=button value="Take Snapshot" onClick="take_snapshot()">
<div id="upload_results" style="background-color:#eee;"></div>
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<input type="text" id="name" name="name" value="<?php echo (isset($_POST['name']) ? $_POST['name'] : ''); ?>" maxlength="40" size="45" tabindex="2">
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<textarea name="add" id="add" row="3" cols="40" tabindex="3">
<?php echo (isset($_POST['vouchdt']) ? $_POST['vouchdt'] : ''); ?>
</textarea>
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<input type="text" id="city" name="city" size="20" maxlength="20" value="<?php echo (isset($_POST['city']) ? $_POST['city'] : ''); ?>" tabindex="4">
Pin
<input type="text" id="pin" name="pin" size="6" maxlength="6" value="<?php echo (isset($_POST['pin']) ? $_POST['pin'] : ''); ?>" tabindex="5">
</td>
</tr>
<tr>
<td>
Nationality
</td>
<td>
<input type="text" id="ntn" name="ntn" value="<?php echo (isset($_POST['ntn']) ? $_POST['ntn'] : ''); ?>" size="10" maxlength="10" tabindex="6">
</td>
</tr>
<tr>
<td>
Mobile No
</td>
<td>
<input type="text" id="mob" name="mob" value="<?php echo (isset($_POST['mob']) ? $_POST['mob'] : ''); ?>" tabindex="7">
</td>
</tr>
<tr>
<td>
Date of Birth
</td>
<td>
<input type="text" id="dob" name="dob" value="<?php echo (isset($_POST['dob']) ? $_POST['dob'] : ''); ?>" id="popupDatepicker2" tabindex="8">
</td>
<td>
Age
</td>
<td width="9px">
<input type="text" id="age" name="age" size="3" maxlength="3" value="<?php echo (isset($_POST['age']) ? $_POST['age'] : ''); ?>" tabindex="9">
</td>
<td width="10px">
Sex
</td>
<td>
<select id="sex" name="sex" tabindex="12">
<?php
if(isset($_POST[sex])==m){
?>
<option value="<?php echo (isset($_POST['sex']) ? $_POST['sex'] : ''); ?>">Male</option>":
<?php }else{?>
<option value="<?php echo (isset($_POST['sex']) ? $_POST['sex'] : ''); ?>">Female</option>":
<?php }?>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</td>
</tr>
<tr>
<td>
Religion
</td>
<td>
<input type="text" id="rel" name="rel" value="<?php echo (isset($_POST['rel']) ? $_POST['rel'] : ''); ?>" size="20" maxlength="20" tabindex="11">
</td>
<td>
Martial Status
</td>
<td>
<select id ="status" name="status" tabindex="12">
<option value="">--select--</option>
<option value="1">Married</option>
<option value="2">Unmarried</option>
</select>
</td>
</tr>
<tr>
<td>
Passport No.
</td>
<td>
<input type="text" id="pass" name="pass" value="" size="15" maxlength="15" tabindex="13">
</td>
<td>
Place of Issue
</td>
<td>
<input type="text" id="poi" name="poi" size="20" maxlenght-20 tabindex="14">
</td>
<td>
Date of Issue
</td>
<td>
<input type="text" id="doi" name="doi" id="popupDatepicker4" tabindex="15">
</td>
</tr>
<tr>
<td>
Profession
</td>
<td>
<input type="text" id="prof" name="prof" size="20" maxlenght="20" value="" tabindex="16">
</td>
<td>
Amount
</td>
<td>
<input type="text" id="amt" name="amt" value="" size ="8" onblur="calculateText()" style="background-color:transparent; color:blue; text-align:right" tabindex="17">
</td>
</tr>
<tr>
<td>
Payment
</td>
<td>
<select id="pay" name="pay" tabindex="12">
<option value="">--select--</option>
<option value="f">Full</option>
<option value="p">Part</option>
<option value="n">None</option>
</select>
</td>
<td>
Received
</td>
<td>
<input type="text" id="resc" name="resc" value="" size ="8" onblur="calculateText()" style="background-color:transparent; color:green; text-align:right" tabindex="18">
</td>
</tr>
<tr>
<td>
Agent
</td>
<td>
<input type="tetx" id="agnt" name="agnt" value="" size="40" maxlength="40" tabindex="21">
</td>
<td>
Balance
</td>
<td>
<input type="text" id="bal" name="bal" readonly="readonly" value="" size ="8" style="background-color:transparent; color:red; text-align:right" onblur="calculateText()" tabindex="19">
</td>
</tr>
<tr>
<td>
Mofa No.
</td>
<td>
<input type="text" id="mofa" name="mofa" value="" size="20" maxlength="20" tabindex="22">
</td>
</tr>
<tr>
<td>
Remarks
</td>
<td>
<input type="text" id="rem" name="rem" size="60" maxlength="60" value="" tabindex="23">
</td>
</tr>
<table border="0" align="center">
<tr>
<td>
<input type="submit" name="save" value="Save"><input type="hidden" name="task" value="addComments" />
<td>
<input type="submit" name="print" value="Print">
</td>
<td>
<input type="submit" name="close" value="Cancel">
</td>
<td>
<input type="reset" name="Add" value="Add">
</td>
</tr>
</table>
</table>
</form>
</body>
</html>
Here is my JavaScript code:
<script type="text/javascript">
jQuery(document).ready(function($){
$("#entry").submit(function(){
ctask = this.task.value;
cvouchdt = this.vouchdt.value;
ccouncde = this.councode.value;
ccounvouch = this.counvouch.value;
cname = this.name.value;
ccity = this.city.value;
cpin = this.pin.value;
cntn = this.ntn.value;
cmob = this.mob.value;
cdob = this.dob.value;
cage = this.age.value;
csex = this.sex.value;
crel = this.rel.value;
cstatus = this.status.value;
cpass = this.pass.value;
crel = this.rel.value;
cpoi = this.poi.value;
cdoi = this.doi.value;
cprof = this.prof.value;
camt = this.amt.value;
cpay = this.pay.value;
cpass = this.pass.value;
crecd = this.recd.value;
cagnt = this.agnt.value;
cbal = this.bal.value;
cmofa = this.mofa.value;
crem = this.rem.value;
save = this.save;
if(cname=="" || ccounvouch=="" || ccouncde=="") { $("#errAll").html('<p>Invalid Captcha. Please try again.</p>'); }
$.post("submit.php", {task: ctask, name: cname, email: cemail, url: curl, message: cmessage}, function(data){
if(data=='0') { $("#errAll").html('<p>Please don\'t leave the requierd fields.</p>'); }
else if(data=='1') { $("#errAll").html('<p>Invalid Email Address, Please try again.</p>'); }
else { submitter.value="Value Saved"; save.disabled=false;} //$(data).appendTo($(".commentpost")); }
});
return false;
});
});
</script>
Here is my PHP code:
<?php
//include_once( 'config.php' );
require("includes/dbconnect.php");
$getmaxvou = mysql_query("SELECT MAX(`vouchno`) as `maxid` FROM `candidate` ") or die(mysql_error());
$max = mysql_fetch_array($getmaxvou);
$maxv =$max["maxid"]+1;
if(isset($_POST['task']) && $_POST['task'] == 'addComments')
{
$a = 1;
$date = mysql_real_escape_string($_POST["vouchdt"]);
$date = strtotime($date);
$date = date('Y-m-d',$date);
$cname = trim($_POST["name"]);
$add = trim($_POST["add"]);
$city = trim($_POST["city"]);
$pin = trim($_POST["pin"]);
$nations = trim($_POST["ntn"]);
$mob = trim($_POST["mob"]);
$dob = mysql_real_escape_string($_POST["dob"]);
$dob = strtotime($dob);
$dob = date('Y-m-d',$dob);
$age = trim($_POST["age"]);
$sex = trim($_POST["sex"]);
$rel = trim($_POST["rel"]);
$pass = trim($_POST["pass"]);
$status = trim($_POST["status"]);
$poi = trim($_POST["poi"]);
$doi = mysql_real_escape_string($_POST["doi"]);
$doi = strtotime($doi);
$doi = date('Y-m-d',$doi);
$prof = trim($_POST["prof"]);
$amt = trim($_POST["amt"]);
$pay = trim($_POST["pay"]);
$bal = trim($_POST["bal"]);
$recd = trim($_POST["resc"]);
$agnt = trim($_POST["agnt"]);
$mofa = trim($_POST["mofa"]);
$rem = trim($_POST["rem"]);
$councode = trim($_POST["councode"]);
$counvouch = trim($_POST["counvouch"]);
{
if (isset($_POST["code"])) {
$sql_check = mysql_query("SELECT * FROM candiidate WHERE code ='$councode' AND counvouch='$counvouch'");
if (mysql_num_rows($sql_check) > 0) {
$a = 0;
print '<script type="text/javascript">';
print 'alert("Code Already Exist For the Country")';
PRINT '</script>';
}
}
if($a ==1){
mysql_query("INSERT INTO `candidate`(vouchno, vouchdt, `name`, `add`, `city`, `pin`, `nationality`, mobile, dob, `religion`, `passport`, `profession`, amt, recd, bal, payment, `agent`, `mofa`, `age`, `gender`, `martial`, `poi`, doi, councode, counvouch, `rem` )
Values
('$maxv', '$date', '$cname', '$add', '$city', '$pin', '$nations', '$mob', '$dob', '$rel', '$pass', '$prof', '$amt', '$recd', '$bal', '$pay', '$agnt', '$mofa', '$age', '$sex', '$status', '$poi', '$doi', '$councode', '$counvouch', '$rem' )") or die(mysql_error());
echo ' <div class="commentbox">
<div class="commentboxt">Value Inserted </div>
</div>';
}
}
}?>
Change form tag to
<form name="entry" id="entry" method="GET" action="javascript:">
that will stop the page from refreshing.
Then look into jquery ajax http://api.jquery.com/jQuery.ajax/
For example.
var string ="FORMVALUE1=" + $('#FORMVALUE1ID').val() + "FORMVALUE2=" + $('#FORMVALUE2ID').val() + "REAPEAT FOR ALL YOUR VALUES";
$.ajax({
type: "GET",
url: "YOURPHPFILE.php",
data: string,
});
Then just get the form values in the php file by using $_GET['FORMVALUE1'];
You first seperate your PHP file where you insert or do some action.
PHP Action File: YourPHPPostFile.php
HTML File: index.html or whatever name you have.
Then in PHP file write all your code but in the begining add check that is
if(isset($_POST['task']) && $_POST['task'] == 'addComments')
{//Your all PHP Code here}
On the other hand in your html file make a AJAX request to this file and use POST Method in AJAX request and include your data within Request Parameters.
One more thing if you don't want to lose your Form data which is filled you can use:
<form name="entry" id="entry" method="GET" onsubmit="calltoAjax();return false;">
Now whenever user submit form then it will not reset the form and data also stored in your database.
Thanks,
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.