Basically what I am doing is adding a contact form module to Open Cart, currently I am only trying to get it working rather than perfect so I only have three fields at the moment.
Name: Email: Comments:
At first I could not get the event handler working, turns out that was down to AJAX for some reason so adding the if ($(event.target).is('#submit')) worked. Technically this should be very easy to do, it does send emails so the PHP side is working but the Javascript does not seem to be getting the values properly.
<form name="contact" action="" method="post">
<fieldset>
<h4>Arrange a Print</h4>
<label for="name">Name: <span class="star">*</span></label>
<input name="name" id="name" type="text" value="" />
<label for="email">email <span class="star">*</span></label>
<input name="email" id="email" type="text" />
<label>Comments / Message:</label>
<textarea name="comments" id="comments"> </textarea>
<div class="button" id="submit">Submit</div>
</fieldset>
</form>
[/quote]
[quote]
$(document).ready(function() {
$("body").click(function(event) {
if ($(event.target).is('#submit')) {
var isError = false;
var errStr = 'Could not proceed further, there is/are some error(s) in your form submission. Have a look on the error(s) below:\n\n';
var varName;
var varEmail;
var varComments;
var varName = $("#name").val();
alert(varName);
if (varName == null) {
errStr += '* Please Enter Your Name.\n';
isError = true;
}
var varEmail = $("#email").val();
if (varEmail == null) {
errStr += '* Please Enter Your Email.\n';
isError = true;
} else {
if (!isValidEmail($.trim(varEmail))) {
errStr += '* Incorrect Email Format.\n';
isError = true;
}
}
if (isError) {
alert(errStr);
}
else {
submitForm();
}
}
});
function isValidEmail(email)
{
var filter = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return filter.test(email);
}
function submitForm()
{
var varComments = $("#comments").val();
var data = 'name=' + varName + '&email=' + varEmail + '&comments=' + varComments;
$.ajax({
type : "post",
url : "/catalog/view/theme/shoppica/template/cms/pricelist_form.php",
data: data,
success : function(msg){
if(msg=="Mail successfully sent")
{
alert("yay");
$("#name").val('');
$("#email").val('');
$("#comments").val('');
}
}
});
}
});
I cannot figure out why it is not working. I am using Open Cart but that should not be any problem with regards to the javascript.
To verify: The problem is that the Javascript is not getting the values from the input boxes. The alert is not showing anything... I don't understand why it is not finding it!
Thanks,
Shane
This post has been edited by Shane Hudson: 09 August 2011 - 02:25 AM

New Topic/Question
Reply


MultiQuote




|