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>'));
Related
This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have created a form and would like the information to be sent to my email using php. The information submits, and I receive an e-mail, but the email only displays the first and last name of input by the individual submitting the form. I would like to know what is missing from either the php side or html side.
Thank You
<form name="contactform" method="post" action="appraisal_form.php">
<table width="500px">
<tr>
<td>
<label for="first_name">First Name *</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name *</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address *</label>
</td>
<td>
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="telephone">Telephone Number</label>
</td>
<td>
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<!--- Property Type-->
<tr>
<td>
<label for="lender">Lender *</label>
</td>
<td>
<input type="text" name="lender" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_officer">Loan Officer *</label>
</td>
<td>
<input type="text" name="loan_officer" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="property_address">Email Address *</label>
</td>
<td>
<input type="text" name="property_address" maxlength="100" size="30">
</td>
</tr>
<tr>
<td>
<label for="city">City *</label>
</td>
<td>
<input type="text" name="city" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="zip">Zip Code *</label>
</td>
<td>
<input type="text" name="zip" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="pin">PIN(Permenant Index Number) *</label>
</td>
<td>
<input type="text" name="pin" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="rooms">Number of Rooms *</label>
</td>
<td>
<input type="text" name="rooms" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="bath">Number of Bathrooms *</label>
</td>
<td>
<input type="text" name="bath" maxlength="80" size="30">
</td>
</tr>
<!--- Garage /yes or no-->
<tr>
<td>
<label for="plat">Plat of Survey *</label>
</td>
<td>
<input type="text" name="plat" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="borrow">Borrowers Name *</label>
</td>
<td>
<input type="text" name="borrow" maxlength="80" size="30">
</td>
</tr>
<!--- sale /refinance-->
<tr>
<td>
<label for="price">Purchase Price *</label>
</td>
<td>
<input type="text" name="price" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_amount">Loan Amount *</label>
</td>
<td>
<input type="text" name="loan" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="cod">C.O.D *</label>
</td>
<td>
<input type="text" name="cod" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="invoice">Invoice *</label>
</td>
<td>
<input type="text" name="invoice" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="comments">Comments *</label>
</td>
<td>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="Reset" id="reset" value="reset">
</td>
</tr>
</table>
</form>
PHP
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$lender = $_POST['lender']; // required
$loan_officer = $_POST['loan_officer']; // required
$property_address = $_POST['property_address']; // required
$city = $_POST['city']; // required
$zip = $_POST['zip']; // not required
$pin = $_POST['pin']; // required
$rooms = $_POST['rooms']; // required
$bath = $_POST['bath']; // required
$plat = $_POST['plat']; // required
$borrow = $_POST['borrow']; // not required
$price = $_POST['price']; // required
$cod = $_POST['cod']; // not required
$comments = $_POST['comments']; // required
$to = "rosaliam2#yahoo.com";
$subject = "New Appraisal Request";
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
mail($to, $subject, $message, "From" . $first_name . $last_name);
echo "Your Information has been sent";
?>
Actually there is no message variable to send!!
you are just sending $first_name and $last_name as headers!
I can't find any solution for my problem. And the things I found don't work. I want to put the variables from a form into an HTML mail. I think I understand the way to get POST variables from a form into an HTML mail, but it doesn't work. This is my PHP script which is in a separate data.php:
mailerneu.php
<?php
error_reporting(E_ALL);
$vorname = $_POST["Vorname"];
$nachname = $_POST["Nachname"];
$email = $_POST["Mailadresse"];
$telefonnumer = $_POST["Telefonnummer"];
$geburtsjahr = $_POST["Geburtsjahr"];
$plz = $_POST["PLZ"];
$datum = $_POST["Datum"];
$zeit = $_POST["Zeit"];
$personen = $_POST["Personen"];
$bereich = $_POST["Bereich"];
$nachricht = $_POST["Nachricht"];
$mailTo = "fixl#bodega-online.de";
$subject = "Tischreservierung";
$from = "From: Bodega Bremerhaven<reservierungen#domain.de>\r\n";
$from .= "Content-Type: text/html; charset; utf8\r\n";
$text = "
<head>
<title>Neue Tischreservierung von <strong>$vorname $nachname</strong></title>
</head>
<body>
<table style='font-family:calibri,sans-serif; font-size: 16pt;'>
<tr>
<td>Vorname:</td>
<td>".htmlspecialchars($vorname)."</td>
</tr>
<tr>
<td>Nachname:</td>
<td>" .$nachname. "</td>
</tr>
<tr>
<td>Email:</td>
<td>" .$email. "</td>
</tr>
<tr>
<td>Telefonnummer:</td>
<td>" .$telefonnummer. "</td>
</tr>
<tr>
<td>Geburtsjahr:</td>
<td>" .$geburtsjahr. "</td>
</tr>
<tr>
<td>PLZ:</td>
<td>" .$plz. "</td>
</tr>
<tr>
<td>Datum:</td>
<td>" .$datum. "</td>
</tr>
<tr>
<td>Uhrzeit:</td>
<td>" .$zeit. "</td>
</tr>
<tr>
<td>Personen:</td>
<td>" .$personen. "</td>
</tr>
<tr>
<td>Bereich:</td>
<td>" .$bereich. "</td>
</tr>
<tr>
<td>Nachricht:</td>
<td>" .$nachricht. "</td>
</tr>
</body>";
mail($mailTo, $subject, $text, $from);
?>
This is the PHP file with my HTML form:
reservierung.php
<?php
include ("mailerneu.php");
?>
<div class="text">
<form method="post" action="reservtrue.php">
<table id="reservtable">
<tr>
<td>
<label for="vornamelbl"><strong id="textreserv">Vorname:</strong></label>
</td>
<td>
<input type="text" name="Vorname" placeholder="Vorname" class="formreserv" id="vornamelbl">
</td>
</tr>
<tr>
<td>
<label for="nachnamelbl"><strong id="textreserv">Nachname:</strong></label>
</td>
<td>
<input type="text" name="Nachname" placeholder="Nachname" class="formreserv" id="nachnamelbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="emaillbl"><strong id="textreserv">e-Mail Adresse:</strong></label>
</td>
<td>
<input type="email" name="Mailadresse" placeholder="Gültige Adresse!" class="formreserv" id="emaillbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="telefonnummerlbl"><strong id="textreserv">Telefonnummer:</strong></label>
</td>
<td>
<input type="tel" name="Telefonnummer" placeholder="Mobil oder Festnetz" min="5" max="20" class="formreserv" id="telefonnummerlbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="geburtsjahrlbl"><strong id="textreserv">Geburtsjahr:</strong></label>
</td>
<td>
<input type="text" name="Geburtsjahr" placeholder="1984" min="4" max="4" class="formreserv" id="geburtsjahrlbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="postleitzahllbl"><strong id="textreserv">Postleitzahl</strong></label>
</td>
<td>
<input type="text" name="PLZ" placeholder="PLZ" min="5" max="5" class="formreserv" id="postleitzahllbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="datumlbl"><strong id="textreserv">Datum der Reservierung:</strong></label>
</td>
<td>
<input type="date" name="Datum" placeholder="Klick" min="10" max="10" class="formreserv" id="datumlbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="uhrzeitlbl"><strong id="textreserv">Uhrzeit:</strong></label>
</td>
<td>
<input type="text" name="Zeit" placeholder="Stunde" min="12" max="21" class="formreservhour" id="uhrzeitlbl" required>
<input type="text" name=" " placeholder="Minute" min="00" max="59" class="formreservminute" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="personenlbl"><strong id="textreserv">Personen:</strong></label>
</td>
<td>
<input type="text" name="Personen" placeholder="1 bis 30" min="1" max="2" class="formreserv" id="personenlbl" required><strong id="required"> *</strong>
</td>
</tr>
<tr>
<td>
<label for="bereichlbl"><strong id="textreserv">Bitte Bereich wählen:</strong></label>
</td>
<td>
<form>
<select name="Bereich" class="dropreserv" id="bereichlbl">
<option>Bereich wählen:</option>
<option>Nichtraucher</option>
<option id="raucher">Raucher</option>
</select><strong id="required"> *</strong>
</form>
</td>
</tr>
<tr>
<td>
<label for="nachrichtlbl"><strong id="textreserv">Nachricht (optional):</strong></label>
</td>
<td>
<textarea name="Nachricht:" class="reservtextarea" id="nachrichtlbl" placeholder="Ihr Text"></textarea>
</td>
</tr>
<tr>
<td>
<label for="click"><strong id="textreserv">Eine Kopie an mich</strong></label>
</td>
<td>
<div class="checkbox">
<input type="checkbox" name="sendcopy" value="copy" id="click">
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="" value="Reservieren" id="submit">
</td>
</tr>
</table>
</form>
</div>
I hope I didn't do lots of mistakes. I get the HTML table in mail. But only the variables are empty in <td>. Hopefully waiting and still researching.
Every time the PHP mailerneu.php file is included, it triggers a mail with empty data as the form has not been submitted yet. So better use the include this way:
if (isset($_POST['Vorname']) {
include ("mailerneu.php");
}
Also, I found a mistake in your HTML form:
name="Nachricht:" - you have added an extra : (double dots). Please verify your HTML form inputs name once.
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.
this is the code I have, I need my message to appear in the top of my form but I got an error.
I need to print my message right where I put the code print $msg
any idea about this please.
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table width="300" border="0">
<tr>
<td colspan="2"><?php print($msg); ?></td>
</tr>
<tr>
<td> *First name</td>
<td><span id="sprytextfield3">
<input type="text" value="" name="RFname" />
<br>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*Last name</td>
<td><span id="sprytextfield4">
<input type="text" value="" name="RLname" />
<br>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*User name</td>
<td><span id="sprytextfield1">
<input type="text" name="UserName" value="" />
<br />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*Password</td>
<td><span id="sprypassword1">
<input type="password" name="UserPass" value="" />
<span class="passwordRequiredMsg"><br />
A value is required.</span></span></td>
</tr>
<tr>
<td>*Email</td>
<td><span id="sprytextfield2">
<input type="text" name="UserEmail" value="" />
<br />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td>Web site</td>
<td><input type="text" name="WebSite" value="" /></td>
</tr>
<tr>
<td> </td>
<td><input name="submited" type="submit" onClick="MM_swapImage('Image1','','images/blog.png',1)" value="Register"/></td>
</tr>
</table>
</form>
</div>
<div class="image_NewUserRegister"><iframe src="images/Untitled-2.jpg" name="now_regist" width="207" height="280" scrolling="no" frameborder="0"></iframe></div>
</div>
<?php
if(isset($_POST['submited'])) {
$RFname = $_POST['RFname'];
$RLname = $_POST['RLname'];
$USERname = $_POST['UserName'];
$USERpassword = $_POST['UserPass'];
$USERemail = $_POST['UserEmail'];
$USERwebsite = $_POST['WebSite'];
$check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'");
if(mysqli_num_rows($check) > 0 ) {
$msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This email already taken</span>";
}
this is the code I have, I need my message to appear in the top of my form but I got an error. I need to print my message right where I put the code print $msg
any idea about this please.
You really need to set the message before you try to output it.
To elaborate on David's answer: move the PHP block before the form markup, like so:
<?php
if(isset($_POST['submited'])) {
$RFname = $_POST['RFname'];
$RLname = $_POST['RLname'];
$USERname = $_POST['UserName'];
$USERpassword = $_POST['UserPass'];
$USERemail = $_POST['UserEmail'];
$USERwebsite = $_POST['WebSite'];
$check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'");
if(mysqli_num_rows($check) > 0 ) {
$msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This email already taken</span>";
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table width="300" border="0">
<tr>
<td colspan="2"><?php print($msg); ?></td>
</tr>
<tr>
<td> *First name</td>
<td><span id="sprytextfield3">
<input type="text" value="" name="RFname" />
<br>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*Last name</td>
<td><span id="sprytextfield4">
<input type="text" value="" name="RLname" />
<br>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*User name</td>
<td><span id="sprytextfield1">
<input type="text" name="UserName" value="" />
<br />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td>*Password</td>
<td><span id="sprypassword1">
<input type="password" name="UserPass" value="" />
<span class="passwordRequiredMsg"><br />
A value is required.</span></span></td>
</tr>
<tr>
<td>*Email</td>
<td><span id="sprytextfield2">
<input type="text" name="UserEmail" value="" />
<br />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td>Web site</td>
<td><input type="text" name="WebSite" value="" /></td>
</tr>
<tr>
<td> </td>
<td><input name="submited" type="submit" onClick="MM_swapImage('Image1','','images/blog.png',1)" value="Register"/></td>
</tr>
</table>
</form>
</div>
<div class="image_NewUserRegister"><iframe src="images/Untitled-2.jpg" name="now_regist" width="207" height="280" scrolling="no" frameborder="0"></iframe></div>
</div>
HTH.