Pete Winter
asked on
jquery validate - load php page first
I am using the below jquery code to validate my form:
However my form code is created via a ajax call to a php page.
So I need to load the php file first before I validate. How can I integrate the above code with the code below???
Hope that makes sense?
$(".QuoteForm").validate({
rules: {
first_name: "required",
last_name: "required",
email: {
required: true,
email: true
}
},
messages: {
first_name: "Please enter your firstname",
last_name: "Please enter your lastname",
email: "Please enter a valid email address"
}
});
However my form code is created via a ajax call to a php page.
So I need to load the php file first before I validate. How can I integrate the above code with the code below???
$("#Selected_Printer_Quote").load('quote_script.php');
Hope that makes sense?
ASKER
Thanks for the reply, but it's not quite working.
Can you please check out the link below to help me work out why?
http://www.cmyukdigital.com/new/quote3.php#printerid_2
JQuery: http://www.cmyukdigital.com/new/js/quote3.js
Is should validate the form fields in the same way that this link does:
http://www.cmyukdigital.com/new/quote2.php
Can you please check out the link below to help me work out why?
http://www.cmyukdigital.com/new/quote3.php#printerid_2
JQuery: http://www.cmyukdigital.com/new/js/quote3.js
Is should validate the form fields in the same way that this link does:
http://www.cmyukdigital.com/new/quote2.php
I'm not at a computer, but I will look at it tonight.
Cheers
Cheers
It appears to me that you are trying to submit the form with Ajax, but you need to validate it first so your fields aren't null. In your question you said you wanted to load the script before validating, but maybe that wasn't quite correct? Am I right? What is the PHP script - post to db?
If I'm right, then you need to do the Ajax call in the submit handler of the validate method.
If I'm right, then you need to do the Ajax call in the submit handler of the validate method.
ASKER
Yes that's correct.
1) I first need to load the form with AJAX as some of the content is based on a URL request.
2) I then need to validate the form
3) Post the form to a database and send an email.
So a submit hander of the validate method sounds correct.
Can you show me how to do this please?
My php code is below...
1) I first need to load the form with AJAX as some of the content is based on a URL request.
2) I then need to validate the form
3) Post the form to a database and send an email.
So a submit hander of the validate method sounds correct.
Can you show me how to do this please?
My php code is below...
<?php require_once('../Connections/conn_cmyuk.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if(isset($_POST["printer_select"])){
mysql_select_db($database_conn_cmyuk, $conn_cmyuk);
$query_rs_printer_select = "SELECT * FROM printer WHERE id = ". $_POST["printerid"];
$rs_printer_select = mysql_query($query_rs_printer_select, $conn_cmyuk) or die(mysql_error());
$row_rs_printer_select = mysql_fetch_assoc($rs_printer_select);
$totalRows_rs_printer_select = mysql_num_rows($rs_printer_select);
}
?>
<div id="printer_quote">
<form action="" method="POST" name="QuoteForm" id="QuoteForm" class="QuoteForm">
<input name="printer_id" type="hidden" id="printer_id" value="<?php echo $row_rs_printer_select['id']; ?>" />
<h1>Get your <?php echo $row_rs_printer_select['name']; ?> Quote Online now!</h1>
<p>Please enter you details below and we will send you a personalised quotation.</p>
<p class="first_name">
<label for="first_name">First Name <span>*</span></label>
<input name="first_name" type="text" id="first_name" size="45"/>
</p>
<p class="last_name">
<label for="last_name">Last Name <span>*</span></label>
<input name="last_name" type="text" id="last_name" size="45" />
</p>
<p class="company">
<label for="company">Company <span>*</span></label>
<input name="company" type="text" id="company" size="45" />
</p>
<p class="address1">
<label for="address1">Address Line 1 <span>*</span></label>
<input name="address1" type="text" id="address1" size="45" />
</p>
<p class="address2">
<label for="address2">Address Line 2</label>
<input name="address2" type="text" id="address2" size="45" />
</p>
<p class="town_city">
<label for="town_city">Town / City <span>*</span></label>
<input name="town_city" type="text" id="town_city" size="45" />
</p>
<p class="county">
<label for="county">County</label>
<input name="county" type="text" id="county" size="45" />
</p>
<p class="post_code">
<label for="post_code">Post Code <span>*</span></label>
<input name="post_code" type="text" id="post_code" size="45" />
</p>
<p class="phone">
<label for="phone">Phone</label>
<input name="phone" type="text" id="phone" size="45" />
</p>
<p class="fax">
<label for="fax">Fax</label>
<input name="fax" type="text" id="fax" size="45" />
</p>
<p class="email">
<label for="email">Email <span>*</span></label>
<input name="email" type="text" id="email" size="45" />
</p>
<input type="submit" name="Quote" id="Quote" value="Send me a Quote" class="Big_Button"/>
</form>
<div id="Quote_Success">
<h1>Quotation Request Sent</h1>
<p>Dear <strong>xxxxx</strong></p>
<p>Thank you for your quotation request for the <strong>xxxx</strong> Printer.</p>
<p>You quotation request has been sent for approval. We will email you a personalised quote shortly.<br />
<br />
Kind Regards<br />
<br />
<strong>CMYUK</strong></p>
<p>If you have any other questions call us on <strong>+44 (0) 118 989 2929</strong> or email <strong><script language="JavaScript" type="text/javascript">
<!-- Begin
document.write('<a href=\"mailto:info'+ '@' + 'cmyuk.com\">');
document.write('info'+ '@' +'cmyuk.com</a>');
// End -->
</script></strong>.</p>
</div>
<?php mysql_free_result($rs_printer_select); ?>
</div>
i ran into the same problem once. The ajax callback is fired on success but is not waiting for the content totally generated by the php file. So your validation fires before the form is created by your php.
I worked around it with a timeout like this:
This is not the most elegant solution but it worked for me. The problem is, that you're not considering the different internet connections of your clients, but you can put it reasonably high so it is still ok for people with high-speed connections to wait and people with low-speed connections will have enough time to load the generated form of your php.
Good luck with it.
I worked around it with a timeout like this:
$(function(){
$("#Selected_Printer_Quote").load('quote_script.php', function(data){
var validateForm = function () {
$(".QuoteForm").validate({
rules: {
first_name: "required",
last_name: "required",
email: {
required: true,
email: true
}
},
messages: {
first_name: "Please enter your firstname",
last_name: "Please enter your lastname",
email: "Please enter a valid email address"
}
});
});
setTimeout(validateForm, 800);
}
});
This is not the most elegant solution but it worked for me. The problem is, that you're not considering the different internet connections of your clients, but you can put it reasonably high so it is still ok for people with high-speed connections to wait and people with low-speed connections will have enough time to load the generated form of your php.
Good luck with it.
try it with the $.ajax function instead of the shortcut. then render your form only after it's completely loaded, and do the validation.
ou don't need a timeout. this will only render the form if the file is fully loaded. That's the whole idea of a callback.
let me know how you get on.
$.ajax({
url: 'quote_script.php',
success: function(data) {
$('#Selected_Printer_Quote').html(data);
$(".QuoteForm").validate({
// Rules
rules: {
first_name: "required",
last_name: "required",
company: "required",
address1: "required",
town_city: "required",
post_code: "required",
email: {
required: true,
email: true
}
},
// Messages
messages: {
first_name: "Enter your firstname",
last_name: "Enter your lastname",
company: "Enter your Company",
address1: "Enter your Address Line 1",
town_city: "Enter your Town / City",
post_code: "Enter your Post Code",
email: "Invalid email address"
},
errorElement: "span",
submitHandler: function() {
$(".QuoteForm").slideUp();
$("#Quote_Success").slideDown();
$("body").scrollTop(0);
}
});
}
});
ou don't need a timeout. this will only render the form if the file is fully loaded. That's the whole idea of a callback.
let me know how you get on.
ASKER
kozaiwaniec - Thanks, but didn't work unfortunately?
I got the below error message in firebug log if that helps?
ReferenceError: Can't find variable: Begin
I got the below error message in firebug log if that helps?
ReferenceError: Can't find variable: Begin
ASKER
mcnute - Thanks for the reply, but I am getting an syntax error. Also I'm worried about is not working with some slow broadband speeds.
"Begin" That's inside a comment line. You have other problems going on.
First of all, I would separate the php script into two files. One that GETs the form, and one that POSTs the form data.
I have to run right now. I'll post something for you in a couple hours.
in the meantime, fix this:
comments are written differently in javascript than html:
First of all, I would separate the php script into two files. One that GETs the form, and one that POSTs the form data.
I have to run right now. I'll post something for you in a couple hours.
in the meantime, fix this:
comments are written differently in javascript than html:
<script language="JavaScript" type="text/javascript">
// Begin
document.write('<a href=\"mailto:info'+ '@' + 'cmyuk.com\">');
document.write('info'+ '@' +'cmyuk.com</a>');
// End
</script>
ASKER
kozaiwaniec - Thanks I will remove that code for now. If you can show me how you suggest to separate the scripts when your back that will be great.
here's a test:
http://candpgeneration.com/EE/EE-form-validate-ajax.html
OK, I thought you were trying to post the data in the same php script, but after actually looking at it you're not (doh! - my bad). So there is no need to separate anything out. If you want to submit the form with Ajax though, you'll need to put your submit php script in the submithandler of the validate method (see comment in js file). I can help you with that if you can post your submit script (I'm assuming it's in the html page since there is no action specified in the form tag?)
Anyway, here's the js:
and a lightly revised php file. Your js was causing issues, i fixed it.
(Also, I changed require_once to include_once, so my example would still work without the connection script, but you can change it back)
http://candpgeneration.com/EE/EE-form-validate-ajax.html
OK, I thought you were trying to post the data in the same php script, but after actually looking at it you're not (doh! - my bad). So there is no need to separate anything out. If you want to submit the form with Ajax though, you'll need to put your submit php script in the submithandler of the validate method (see comment in js file). I can help you with that if you can post your submit script (I'm assuming it's in the html page since there is no action specified in the form tag?)
Anyway, here's the js:
$(function(){
$.ajax({
url: 'quote_script.php',
success: function(data) {
$('#Selected_Printer_Quote').html(data);
$(".QuoteForm").validate({
// Rules
rules: {
first_name: "required",
last_name: "required",
company: "required",
address1: "required",
town_city: "required",
post_code: "required",
email: {
required: true,
email: true
}
},
// Messages
messages: {
first_name: "Enter your firstname",
last_name: "Enter your lastname",
company: "Enter your Company",
address1: "Enter your Address Line 1",
town_city: "Enter your Town / City",
post_code: "Enter your Post Code",
email: "Invalid email address"
},
errorElement: "span",
submitHandler: function() {
// ajax form submission goes here
$(".QuoteForm").slideUp();
$("#Quote_Success").slideDown();
$("body").scrollTop(0);
}
});
}
});
});
and a lightly revised php file. Your js was causing issues, i fixed it.
(Also, I changed require_once to include_once, so my example would still work without the connection script, but you can change it back)
<?php include_once('../Connections/conn_cmyuk.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if (isset($_POST["printer_select"])) {
mysql_select_db($database_conn_cmyuk, $conn_cmyuk);
$query_rs_printer_select = "SELECT * FROM printer WHERE id = " . $_POST["printerid"];
$rs_printer_select = mysql_query($query_rs_printer_select, $conn_cmyuk) or die(mysql_error());
$row_rs_printer_select = mysql_fetch_assoc($rs_printer_select);
$totalRows_rs_printer_select = mysql_num_rows($rs_printer_select);
}
?>
<div id="printer_quote">
<form action="" method="POST" name="QuoteForm" id="QuoteForm" class="QuoteForm">
<input name="printer_id" type="hidden" id="printer_id" value="<?php echo $row_rs_printer_select['id']; ?>" />
<h1>Get your <?php echo $row_rs_printer_select['name']; ?> Quote Online now!</h1>
<p>Please enter you details below and we will send you a personalised quotation.</p>
<p class="first_name">
<label for="first_name">First Name <span>*</span></label>
<input name="first_name" type="text" id="first_name" size="45"/>
</p>
<p class="last_name">
<label for="last_name">Last Name <span>*</span></label>
<input name="last_name" type="text" id="last_name" size="45" />
</p>
<p class="company">
<label for="company">Company <span>*</span></label>
<input name="company" type="text" id="company" size="45" />
</p>
<p class="address1">
<label for="address1">Address Line 1 <span>*</span></label>
<input name="address1" type="text" id="address1" size="45" />
</p>
<p class="address2">
<label for="address2">Address Line 2</label>
<input name="address2" type="text" id="address2" size="45" />
</p>
<p class="town_city">
<label for="town_city">Town / City <span>*</span></label>
<input name="town_city" type="text" id="town_city" size="45" />
</p>
<p class="county">
<label for="county">County</label>
<input name="county" type="text" id="county" size="45" />
</p>
<p class="post_code">
<label for="post_code">Post Code <span>*</span></label>
<input name="post_code" type="text" id="post_code" size="45" />
</p>
<p class="phone">
<label for="phone">Phone</label>
<input name="phone" type="text" id="phone" size="45" />
</p>
<p class="fax">
<label for="fax">Fax</label>
<input name="fax" type="text" id="fax" size="45" />
</p>
<p class="email">
<label for="email">Email <span>*</span></label>
<input name="email" type="text" id="email" size="45" />
</p>
<input type="submit" name="Quote" id="Quote" value="Send me a Quote" class="Big_Button"/>
</form>
<div id="Quote_Success">
<h1>Quotation Request Sent</h1>
<p>Dear <strong>xxxxx</strong></p>
<p>Thank you for your quotation request for the <strong>xxxx</strong> Printer.</p>
<p>You quotation request has been sent for approval. We will email you a personalised quote shortly.<br />
<br />
Kind Regards<br />
<br />
<strong>CMYUK</strong></p>
<p class="moreinfo">If you have any other questions call us on <strong>+44 (0) 118 989 2929</strong> or email
<script language="JavaScript" type="text/javascript">
$(".moreinfo").append('<strong><a href=\"mailto:info'+ '@' + 'cmyuk.com\">info'+ '@' +'cmyuk.com</a></strong>.');
</script>
</p>
</div>
<?php mysql_free_result($rs_printer_select); ?>
</div>
ASKER
Many thanks. Thats working, but you have removed the query code at the top.
I needed this to pull in the data on page load. How can I integrate into your supplied code so both are working?
Really appreciate your help! :)
var hash = window.location.hash;
if (hash.substring(0, 11).toLowerCase() == "#printerid_" && hash.length > 11) {
$("#Selected_Printer_Quote").load('quote_script.php', {
printerid: hash.substring(11),
printer_select: "true"
}, function() {
$("#brand_names").hide();
$("#BrandGoBack").show();
$("#printer_names").hide();
$("#PrinterGoBack").show();
$(".enter_details").show();
});
} else {
$("#Selected_Printer_Quote").html('<h1 class="Red">No printer has been selected!</h1>')
}
I needed this to pull in the data on page load. How can I integrate into your supplied code so both are working?
Really appreciate your help! :)
oh right, sorry.
http://localhost:8888/candp/EE/EE-form-validate-ajax.html
pretend a printer was selected:
http://localhost:8888/candp/EE/EE-form-validate-ajax.html#printerid_2.html
and the revised script:
http://localhost:8888/candp/EE/EE-form-validate-ajax.html
pretend a printer was selected:
http://localhost:8888/candp/EE/EE-form-validate-ajax.html#printerid_2.html
and the revised script:
$(function(){
var hash = window.location.hash;
if (hash.substring(0, 11).toLowerCase() == "#printerid_" && hash.length > 11) {
$.ajax({
url: 'quote_script.php',
data: {
printerid: hash.substring(11),
printer_select: "true"
},
success: function(data) {
$('#Selected_Printer_Quote').html(data);
$(".QuoteForm").validate({
// Rules
rules: {
first_name: "required",
last_name: "required",
company: "required",
address1: "required",
town_city: "required",
post_code: "required",
email: {
required: true,
email: true
}
},
// Messages
messages: {
first_name: "Enter your firstname",
last_name: "Enter your lastname",
company: "Enter your Company",
address1: "Enter your Address Line 1",
town_city: "Enter your Town / City",
post_code: "Enter your Post Code",
email: "Invalid email address"
},
errorElement: "span",
submitHandler: function() {
$(".QuoteForm").slideUp();
$("#Quote_Success").slideDown();
$("body").scrollTop(0);
}
});
$("#brand_names").hide();
$("#BrandGoBack").show();
$("#printer_names").hide();
$("#PrinterGoBack").show();
$(".enter_details").show();
}
});
} else {
$("#Selected_Printer_Quote").html('<h1 class="Red">No printer has been selected!</h1>')
}
});
ASKER
Thanks, but there is something that is still not correct. Your links are also local links so I can't test your end.
See this link: http://www.cmyukdigital.com/new/quote4.php#printerid_2
It is not pulling in the data from the php file. I know there is not an error which the php file as this link works with out the validation.
http://www.cmyukdigital.com/new/quote3.php#printerid_2
Notice the heading. It should say "Get your HP Scitex FB500 Quote Online now!"
See this link: http://www.cmyukdigital.com/new/quote4.php#printerid_2
It is not pulling in the data from the php file. I know there is not an error which the php file as this link works with out the validation.
http://www.cmyukdigital.com/new/quote3.php#printerid_2
Notice the heading. It should say "Get your HP Scitex FB500 Quote Online now!"
oops, here are the live links:
http://candpgeneration.com/EE/EE-form-validate-ajax.html
http://candpgeneration.com/EE/EE-form-validate-ajax.html#printerid_2.html
try it this way:
http://candpgeneration.com/EE/EE-form-validate-ajax.html
http://candpgeneration.com/EE/EE-form-validate-ajax.html#printerid_2.html
try it this way:
$(function(){
var hash = window.location.hash;
if (hash.substring(0, 11).toLowerCase() == "#printerid_" && hash.length > 11) {
$.ajax({
url: 'quote_script.php',
data: {
printerid: hash.substring(11),
printer_select: "true"
},
processData: false,
success: function(data) {
$('#Selected_Printer_Quote').html(data);
$(".QuoteForm").validate({
// Rules
rules: {
first_name: "required",
last_name: "required",
company: "required",
address1: "required",
town_city: "required",
post_code: "required",
email: {
required: true,
email: true
}
},
// Messages
messages: {
first_name: "Enter your firstname",
last_name: "Enter your lastname",
company: "Enter your Company",
address1: "Enter your Address Line 1",
town_city: "Enter your Town / City",
post_code: "Enter your Post Code",
email: "Invalid email address"
},
errorElement: "span",
submitHandler: function() {
$(".QuoteForm").slideUp();
$("#Quote_Success").slideDown();
$("body").scrollTop(0);
}
});
$("#brand_names").hide();
$("#BrandGoBack").show();
$("#printer_names").hide();
$("#PrinterGoBack").show();
$(".enter_details").show();
}
});
} else {
$("#Selected_Printer_Quote").html('<h1 class="Red">No printer has been selected!</h1>')
}
});
OK, change this line to use GET:
$query_rs_printer_select = "SELECT * FROM printer WHERE id = " . $_GET["printerid"];
and revert back to this version of the script:
this should really work now :o
$query_rs_printer_select = "SELECT * FROM printer WHERE id = " . $_GET["printerid"];
and revert back to this version of the script:
$(function(){
var hash = window.location.hash;
if (hash.substring(0, 11).toLowerCase() == "#printerid_" && hash.length > 11) {
$.ajax({
//type: "GET",
url: "quote_script.php",
data: {
printerid: hash.substring(11),
printer_select: "true"
},
success: function(data) {
$("#Selected_Printer_Quote").html(data);
$(".QuoteForm").validate({
// Rules
rules: {
first_name: "required",
last_name: "required",
company: "required",
address1: "required",
town_city: "required",
post_code: "required",
email: {
required: true,
email: true
}
},
// Messages
messages: {
first_name: "Enter your firstname",
last_name: "Enter your lastname",
company: "Enter your Company",
address1: "Enter your Address Line 1",
town_city: "Enter your Town / City",
post_code: "Enter your Post Code",
email: "Invalid email address"
},
errorElement: "span",
submitHandler: function() {
$(".QuoteForm").slideUp();
$("#Quote_Success").slideDown();
$("body").scrollTop(0);
}
});
$("#brand_names").hide();
$("#BrandGoBack").show();
$("#printer_names").hide();
$("#PrinterGoBack").show();
$(".enter_details").show();
}
});
} else {
$("#Selected_Printer_Quote").html("<h1 class='Red'>No printer has been selected!</h1>")
}
});
this should really work now :o
ASKER
Still no good unfortunately. It's not pulling in the data?
are you getting the # string in the url when you select a printer to start with?
post another link to your latest file. cheers.
post another link to your latest file. cheers.
ASKER
I'm getting a blank page: http://www.cmyukdigital.com/new/quote4.php#printerid_2
we're getting there. please post your php script.
I have to run, i'll be back in a little while...
I have to run, i'll be back in a little while...
ASKER
<?php require_once('../Connectio ns/conn_cm yuk.php'); ?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if(isset($_POST["printer_s elect"])){
mysql_select_db($database_ conn_cmyuk , $conn_cmyuk);
$query_rs_printer_select = "SELECT * FROM printer WHERE id = ". $_GET["printerid"];
$rs_printer_select = mysql_query($query_rs_prin ter_select , $conn_cmyuk) or die(mysql_error());
$row_rs_printer_select = mysql_fetch_assoc($rs_prin ter_select );
$totalRows_rs_printer_sele ct = mysql_num_rows($rs_printer _select);
}
?>
<div id="printer_quote">
<form action="" method="POST" name="QuoteForm" id="QuoteForm" class="QuoteForm">
<input name="printer_id" type="hidden" id="printer_id" value="<?php echo $row_rs_printer_select['id ']; ?>" />
<h1>Get your <?php echo $row_rs_printer_select['na me']; ?> Quote Online now!</h1>
<p>Please enter you details below and we will send you a personalised quotation.</p>
<p class="first_name">
<label for="first_name">First Name <span>*</span></label>
<input name="first_name" type="text" id="first_name" size="45"/>
</p>
<p class="last_name">
<label for="last_name">Last Name <span>*</span></label>
<input name="last_name" type="text" id="last_name" size="45" />
</p>
<p class="company">
<label for="company">Company <span>*</span></label>
<input name="company" type="text" id="company" size="45" />
</p>
<p class="address1">
<label for="address1">Address Line 1 <span>*</span></label>
<input name="address1" type="text" id="address1" size="45" />
</p>
<p class="address2">
<label for="address2">Address Line 2</label>
<input name="address2" type="text" id="address2" size="45" />
</p>
<p class="town_city">
<label for="town_city">Town / City <span>*</span></label>
<input name="town_city" type="text" id="town_city" size="45" />
</p>
<p class="county">
<label for="county">County</label >
<input name="county" type="text" id="county" size="45" />
</p>
<p class="post_code">
<label for="post_code">Post Code <span>*</span></label>
<input name="post_code" type="text" id="post_code" size="45" />
</p>
<p class="phone">
<label for="phone">Phone</label>
<input name="phone" type="text" id="phone" size="45" />
</p>
<p class="fax">
<label for="fax">Fax</label>
<input name="fax" type="text" id="fax" size="45" />
</p>
<p class="email">
<label for="email">Email <span>*</span></label>
<input name="email" type="text" id="email" size="45" />
</p>
<input type="submit" name="Quote" id="Quote" value="Send me a Quote" class="Big_Button"/>
</form>
<div id="Quote_Success">
<h1>Quotation Request Sent</h1>
<p>Dear <strong>xxxxx</strong></p>
<p>Thank you for your quotation request for the <strong>xxxx</strong> Printer.</p>
<p>You quotation request has been sent for approval. We will email you a personalised quote shortly.<br />
<br />
Kind Regards<br />
<br />
<strong>CMYUK</strong></p>
<p>If you have any other questions call us on <strong>+44 (0) 118 989 2929</strong> or email <strong><script language="JavaScript" type="text/javascript">
<!-- Begin
document.write('<a href=\"mailto:info'+ '@' + 'cmyuk.com\">');
document.write('info'+ '@' +'cmyuk.com</a>');
// End -->
</script></strong>.</p>
</div>
<?php mysql_free_result($rs_prin ter_select ); ?>
</div>
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_rea
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if(isset($_POST["printer_s
mysql_select_db($database_
$query_rs_printer_select = "SELECT * FROM printer WHERE id = ". $_GET["printerid"];
$rs_printer_select = mysql_query($query_rs_prin
$row_rs_printer_select = mysql_fetch_assoc($rs_prin
$totalRows_rs_printer_sele
}
?>
<div id="printer_quote">
<form action="" method="POST" name="QuoteForm" id="QuoteForm" class="QuoteForm">
<input name="printer_id" type="hidden" id="printer_id" value="<?php echo $row_rs_printer_select['id
<h1>Get your <?php echo $row_rs_printer_select['na
<p>Please enter you details below and we will send you a personalised quotation.</p>
<p class="first_name">
<label for="first_name">First Name <span>*</span></label>
<input name="first_name" type="text" id="first_name" size="45"/>
</p>
<p class="last_name">
<label for="last_name">Last Name <span>*</span></label>
<input name="last_name" type="text" id="last_name" size="45" />
</p>
<p class="company">
<label for="company">Company <span>*</span></label>
<input name="company" type="text" id="company" size="45" />
</p>
<p class="address1">
<label for="address1">Address Line 1 <span>*</span></label>
<input name="address1" type="text" id="address1" size="45" />
</p>
<p class="address2">
<label for="address2">Address Line 2</label>
<input name="address2" type="text" id="address2" size="45" />
</p>
<p class="town_city">
<label for="town_city">Town / City <span>*</span></label>
<input name="town_city" type="text" id="town_city" size="45" />
</p>
<p class="county">
<label for="county">County</label
<input name="county" type="text" id="county" size="45" />
</p>
<p class="post_code">
<label for="post_code">Post Code <span>*</span></label>
<input name="post_code" type="text" id="post_code" size="45" />
</p>
<p class="phone">
<label for="phone">Phone</label>
<input name="phone" type="text" id="phone" size="45" />
</p>
<p class="fax">
<label for="fax">Fax</label>
<input name="fax" type="text" id="fax" size="45" />
</p>
<p class="email">
<label for="email">Email <span>*</span></label>
<input name="email" type="text" id="email" size="45" />
</p>
<input type="submit" name="Quote" id="Quote" value="Send me a Quote" class="Big_Button"/>
</form>
<div id="Quote_Success">
<h1>Quotation Request Sent</h1>
<p>Dear <strong>xxxxx</strong></p>
<p>Thank you for your quotation request for the <strong>xxxx</strong> Printer.</p>
<p>You quotation request has been sent for approval. We will email you a personalised quote shortly.<br />
<br />
Kind Regards<br />
<br />
<strong>CMYUK</strong></p>
<p>If you have any other questions call us on <strong>+44 (0) 118 989 2929</strong> or email <strong><script language="JavaScript" type="text/javascript">
<!-- Begin
document.write('<a href=\"mailto:info'+ '@' + 'cmyuk.com\">');
document.write('info'+ '@' +'cmyuk.com</a>');
// End -->
</script></strong>.</p>
</div>
<?php mysql_free_result($rs_prin
</div>
if you wanna try the timeout a last time. The code i posted was wrong, the timeout was fired in the function itselt. that doesn't work.
$(function(){
$("#Selected_Printer_Quote").load('quote_script.php', function(data){
var validateForm = function () {
$(".QuoteForm").validate({
rules: {
first_name: "required",
last_name: "required",
email: {
required: true,
email: true
}
},
messages: {
first_name: "Please enter your firstname",
last_name: "Please enter your lastname",
email: "Please enter a valid email address"
}
});
});
}
setTimeout(validateForm, 800);
});
I'm on the train now so I can't do much, but..
If you click on the link to my test page, you can see that using GET the id is returned. Now granted, I've passed over all the database stuff in my example for obvious reasons.
Do a little test:
Instead of reqire_once, write include_once to rule out the connection not working. Then move the $_get directly into the HTML (this is just a test) . Instead of echoing the printer name, just echo the id for now:
<?php echo $_GET["printerid"]; ?>
I'm trying to troubleshoot one piece at a time. So we're bypassing the db query for now.
Lol..trying to type code on an iPad is no fun...
Believe it or not, I think this actually really close. Btw, a timeout is not going to fix the fact that you're using GET in the Ajax and POST in the PHP.
If you click on the link to my test page, you can see that using GET the id is returned. Now granted, I've passed over all the database stuff in my example for obvious reasons.
Do a little test:
Instead of reqire_once, write include_once to rule out the connection not working. Then move the $_get directly into the HTML (this is just a test) . Instead of echoing the printer name, just echo the id for now:
<?php echo $_GET["printerid"]; ?>
I'm trying to troubleshoot one piece at a time. So we're bypassing the db query for now.
Lol..trying to type code on an iPad is no fun...
Believe it or not, I think this actually really close. Btw, a timeout is not going to fix the fact that you're using GET in the Ajax and POST in the PHP.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hipee :)
Many thanks. You have been a massive help!
Many thanks. You have been a massive help!
:)
try using a callback function in the load method.
Open in new window