http://webexpedition18.com/download/signup_form_WebExpedition18/
Hi Guys,
The above multi-stage contact form works great for my own project. It looks great and does the trick but i am stumped when trying to get the information submitted via email.
So i have a nice looking form but it wont send any information so is pretty useless to me. Even when i just upload the untouched demo files from the tutorial site, it still doesn't work.
Here's the html i have:
<div id="container">
<form action="contact.php" method="post">
<div id="first_step">
<div class="form">
<label for="full-name">Full Name:</label> <input id="username"
name="full-name" style="margin-bottom:10px;" type="text" value=
""> <label for="telephone">Telephone:</label> <input id=
"username" name="telephone" style="margin-bottom:10px;" type=
"text" value=""> <label for="email-address">Email
Address:</label> <input id="username" name="email-address"
style="margin-bottom:10px;" type="text" value="">
</div>
<div class="clear"></div><input class="submit" id="submit_first"
name="submit_first" type="submit" value="Next">
</div>
<div class="clear"></div>
<div id="second_step">
<div class="form">
<label for="company-name">Company Name (if you have
one):</label> <input id="username" name="company-name" style=
"margin-bottom:10px;" type="text" value=""> <label for=
"existing-website">Existing Website (if you have one):</label>
<input id="username" name="existing-website" style=
"margin-bottom:10px;" type="text" value=""> <label for=
"existing-domain">What domain would you like the new website to
be on?</label> <input id="username" name="existing-domain"
style="margin-bottom:10px;" type="text" value="">
</div>
<div class="clear"></div><input class="submit" id="submit_second"
name="submit_second" type="submit" value="Next">
</div>
<div class="clear"></div>
<div id="third_step">
<div class="form">
<label for="which-package">Which package would you
like?:</label>
<p><label><input id="RadioGroup1_0" name="RadioGroup1" type=
"radio" value="Standard"> Standard</label> <label><input id=
"RadioGroup1_1" name="RadioGroup1" type="radio" value=
"Business"> Business</label> <label><input id="RadioGroup1_2"
name="RadioGroup1" type="radio" value="Professional">
Professional</label></p><label for="which-template">Which
template would you like?:</label>
<p><label><input id="RadioGroup2_0" name="RadioGroup2" type=
"radio" value="1"> 1</label> <label><input id=
"RadioGroup2_1" name="RadioGroup2" type="radio" value=
"2"> 2</label> <label><input id="RadioGroup2_2"
name="RadioGroup2" type="radio" value="3">
3</label></p>
<div class="clear"></div>
</div>
<div class="clear"></div><input class="submit" id="submit_third"
name="submit_third" type="submit" value="Next">
</div>
<div class="clear"></div>
<div id="fourth_step">
<div class="form">
<h2>All done ...</h2>
<p style="margin-top:30px;">Press 'Submit' and we'll send you
everything you need to get you up and running.</p>
</div>
<div class="clear"></div><input class="send submit" id=
"submit_fourth" name="submit_fourth" type="submit" value="Submit">
</div>
</form>
</div>
</div>
The submit button just doesn't do anything. I have tried a number of different php form handler codes in my contact.php file but i still get nothing.
Any help is hugely appreciated guys. I'm getting really desperate now after 6 hours trying with this.
Thank you.
The JS file that comes with the demo is:
$(function(){
//original field values
var field_values = {
//id : value
'username' : 'username',
'password' : 'password',
'cpassword' : 'password',
'firstname' : 'first name',
'lastname' : 'last name',
'email' : 'email address'
};
//inputfocus
$('input#username').inputfocus({ value: field_values['username'] });
$('input#password').inputfocus({ value: field_values['password'] });
$('input#cpassword').inputfocus({ value: field_values['cpassword'] });
$('input#lastname').inputfocus({ value: field_values['lastname'] });
$('input#firstname').inputfocus({ value: field_values['firstname'] });
$('input#email').inputfocus({ value: field_values['email'] });
//reset progress bar
$('#progress').css('width','0');
$('#progress_text').html('0% Complete');
//first_step
$('form').submit(function(){ return false; });
$('#submit_first').click(function(){
//remove classes
$('#first_step input').removeClass('error').removeClass('valid');
//ckeck if inputs aren't empty
var fields = $('#first_step input[type=text], #first_step input[type=password]');
var error = 0;
fields.each(function(){
var value = $(this).val();
if( value.length<4 || value==field_values[$(this).attr('id')] ) {
$(this).addClass('error');
$(this).effect("shake", { times:3 }, 50);
error++;
} else {
$(this).addClass('valid');
}
});
if(!error) {
if( $('#password').val() != $('#cpassword').val() ) {
$('#first_step input[type=password]').each(function(){
$(this).removeClass('valid').addClass('error');
$(this).effect("shake", { times:3 }, 50);
});
return false;
} else {
//update progress bar
$('#progress_text').html('33% Complete');
$('#progress').css('width','113px');
//slide steps
$('#first_step').slideUp();
$('#second_step').slideDown();
}
} else return false;
});
$('#submit_second').click(function(){
//remove classes
$('#second_step input').removeClass('error').removeClass('valid');
var emailPattern = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var fields = $('#second_step input[type=text]');
var error = 0;
fields.each(function(){
var value = $(this).val();
if( value.length<1 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='email' && !emailPattern.test(value) ) ) {
$(this).addClass('error');
$(this).effect("shake", { times:3 }, 50);
error++;
} else {
$(this).addClass('valid');
}
});
if(!error) {
//update progress bar
$('#progress_text').html('66% Complete');
$('#progress').css('width','226px');
//slide steps
$('#second_step').slideUp();
$('#third_step').slideDown();
} else return false;
});
$('#submit_third').click(function(){
//update progress bar
$('#progress_text').html('100% Complete');
$('#progress').css('width','339px');
//prepare the fourth step
var fields = new Array(
$('#username').val(),
$('#password').val(),
$('#email').val(),
$('#firstname').val() + ' ' + $('#lastname').val(),
$('#age').val(),
$('#gender').val(),
$('#country').val()
);
var tr = $('#fourth_step tr');
tr.each(function(){
//alert( fields[$(this).index()] )
$(this).children('td:nth-child(2)').html(fields[$(this).index()]);
});
//slide steps
$('#third_step').slideUp();
$('#fourth_step').slideDown();
});
$('#submit_fourth').click(function(){
//send information to server
alert('Sent. Thank you!');
});
});
And the php is used within my contact.php file was:
<?php
$errors = '';
$myemail = 'yourname#website.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
$('form').submit(function(){ return false; }); tells that submit should return false
Related
This Jquery code isn't displaying my error message atleast... Each time i submit the form i expect a success or error message but it doesn't seem like it is responding...
<form method="POST" id="comment_form">
<div class="form-group">
<input type="text" name="comment_name" id="comment_name" class="form-control" placeholder="Enter Name">
</div>
<div class="form-group">
<textarea name="comment_content" id="comment_content" class="form-control" placeholder="Enter your comment" cols="30" rows="5"></textarea>
</div>
<div class="form-group">
<input type="hidden" name="comment_id" id="comment_id" value="0">
<input type="submit" name="submit" id="submit" class="btn btn-info" value="submit">
</div>
</form>
<span id="comment_message"></span>
//add_comment.php page
<?php require_once("../include/database.php"); ?>
<?php
$error = $comment_name = $comment_content = "";
if(empty($_POST["comment_name"])){
$error .= '<p class="text-danger">Name is required</p>';
}else{
$comment_name = $_POST["comment_name"];
}
if(empty($_POST["comment_content"])){
$error .= '<p class="text-danger">Comment is required</p>';
}else{
$comment_content = $_POST["comment_content"];
}
if($error == ''){
// $comments = new Comment();
// $comments->parent_comment_id = $_POST["comment_id"];
// $comments->comment = $comments;
// $comments->comment_sender_name = $comment_name;
// $comments->save();
$sql = "INSERT INTO comments (parent_comment_id, comment, comment_sender_name)
VALUES (:parent_comment_id, :comment, :comment_sender_name)";
$statement = $database->query($sql = array(
':parent_comment_id' => $_POST["comment_id"],
':comment' => $comment_content,
':comment_sender_name' => $comment_name
)
);
$error = '<label class="text-success">Comment Added</label>';
}
$data = array(
'error' => $error
);
echo json_encode($data);
?>
//Jquery code
$(document).ready(function(){
$('#comment_form').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax({
url:"add_comment.php",
method:"POST",
data:{form_data:form_data},
dataType:"json",
success:function(data){
if(data.error != ''){
$('#comment_form')[0].reset();
$('#comment_message').html(data.error);
}
}
});
});
});
Please i need to know why the submit button isn't responding...
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
The necessary bootstrap and jquery libraries were added...
I'm working on a form validation with jQuery and PHP, currently using the AJAX jquery method. PHP file doesn't show up in the Networks tab in the browser developer console. I debugged my code and couldn't see where it went wrong.
Can you guys please give me a few pointers to where I missed out in my code?
HTML
<form action="process.php" method="POST">
<h1 class="display-4 form-heading col-md-9">Now's the time to adopt a <span class="highlight">better</span> email security solution</h1>
<p class="form-copy col-md-9">Let us help you migrate and enhance your email security.</p>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputFirstName">First Name:</label>
<input type="text" class="form-control" id="inputFirstName" name="FirstName" placeholder="333333" required>
</div>
<div class="form-group col-md-6">
<label for="inputLastName">Last Name:</label>
<input type="text" class="form-control" id="inputLastName" name="LastName" placeholder="Last Name" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail">Email Address:</label>
<input type="email" class="form-control" id="inputEmail" name="Email" placeholder="aaa" required>
<div class="form-valid-feedback" id="email-error"></div>
</div>
</form>
Javascript
$(document).ready(function(){
$('form').submit(function(event){
event.preventDefault();
//beginning AJAX
function checkEmail(email){
var re = /\S+#\S+\.\S+/;
return re.test(email);
}
function checkPhoneNumber(phone){
var phonePattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
return phonePattern.test(phone);
}
var FirstName = $("#inputFirstName").val();
var LastName = $("#nputLastName").val();
var email = $("#inputEmail").val();
var companyName = $("#inputCompanyName").val();
var phone = $("#inputPhone").val();
var submit = $("#inputsubmit").val();
var formData = {
FirstName : $("#inputFirstName").val(),
LastName : $("#nputLastName").val(),
email : $("#inputEmail").val(),
companyName : $("#inputCompanyName").val(),
phone : $("#inputPhone").val(),
submit: $("#inputsubmit").val()
};
$.ajax({
type: 'POST',
url : 'process.php',
data:formData
})
if(!data.success){
if(data.errors.firstName){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html(data.errors.firstName);
}
if(data.errors.LastName){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html(data.errors.LastName);
}
if(data.errors.email){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html(data.errors.email);
}
if(data.errors.CompanyName){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html(data.errors.CompanyName);
}
if(data.errors.Phone){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html(data.errors.Phone);
}
}
else if(!checkEmail(email)){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html('Please enter a vlid email address: example#example.com');
}
else if (!checkPhoneNumber(phone)){
$(".form-valid-feedback").show();
$(".form-valid-feedback").html('Please enter a vlid Phone Number: 333-333-3333');
}
else{
$('form').append('<div class="alert alert-success" id="success">' + data.message + '</div>');
}
})
.fail(function(data){
console.log(data)
});
});
//end of submit event handling
});
PHP
<?php
$errors = array();
$data = array();
//starting the validation of variables
if (empty($_POST['FirstName']))
$errors['FirstName'] = "First Name is required.";
if (empty($_POST['LastName']))
$errors['LastName'] = "Last Name is required.";
if (empty($_POST['Email']))
$errors['Email'] = 'Email is required.';
if (empty($_POST['CompanyName']))
$errors['CompanyName'] = 'Company Name is required.';
if (empty($_POST['Phone']))
$errors['Phone'] = 'Phone Number is required.';
if(! empty($errors)) {
$data['success'] = false;
$data['errors'] = $errors;
}
else{
//when everything is free of errors
$data['success'] = true;
$data['message'] = 'Success!';
}
echo json_encode($data);
?>
I am creating custom form in php and using database. I want to integrate that form in wordpress; for this i create one template(customform.php) and adding in page. My php code is smoothly running on xampp but not in wordpress.
Please help me to integrate code in wordpress.
/*CustomForm php*/
<?php /* Template Name: CustomForm */ ?>
<?php require_once("conn.php");?>
<?php get_header(); ?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<div id="content" class="full-width">
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<body>
<form name="course_information" id="course_information" method="post" action="course_information_action.php" >
<div>
<h1 class="heading">Product Details</h1>
<h3>Product Type</h3>
<?php
$sql = "select id,course from course_master";
$result = mysqli_query($con,$sql);
$selectbox = '';
$selectbox .= '<select id="course_master" name="course_master" class="select_style"><option value="0"> -- select --</option>';
while($data = mysqli_fetch_assoc($result))
{
$selectbox .= "<option value=".$data['id'].">".$data['course']."</option>";
}
$selectbox .= '</select>';
echo $selectbox;
?>
<h3>Product</h3>
<div><select class="select_style" id="course_details" name="course_details" >
<option value="0"> -- select --</option>
</select></div>
<p></p>
<div id="ex_data">
<input type="checkbox" name="check" id="check" value="" /> I need a product demonstration, installation assistance and for other queries at no additional cost</div>
<p></p>
<div id="after_check">
<div><textarea rows="5" cols="50" name="requirements" id="requirements" placeholder="Please provide your requirement here"></textarea></div>
<h3>Address</h3>
<div><textarea rows="5" cols="50" name="address" id="address" placeholder="Please provide your address for visit purpose"></textarea></div>
</div>
<span id="key_val">
<h3>Please enter existing serial for extend subscription: </h3>
<div><input type="text" name="key" id="key" value="" /></div>
</span>
<h3>No. of licenses<span class="star_require">*</span> : </h3>
<div><input type="text" name="licenses" id="licenses" value="" required /></div>
<h3>Sub Total : </h3>
<span id="sub_total"></span>
<div><input type="hidden" name="price" id="hidden_subtotal" value="" /></div>
<div><input class="form_btn" type="submit" id="continue_first" value="continue" /></div>
</div>
<div id="contact_details">
h1 class="heading">Contact Details</h1>
<h3>Email Address<span class="star_require">*</span>:</h3>
<div><input type="text" id="email" name="email" value="" required /></div>
<h3>Mobile <span class="star_require">*</span>: </h3>
<div><input type="text" id="mobile" name="mobile" value="" maxlength="10" required /></div>
<div><input class="form_btn" type="submit" id="continue" value="continue" /></div>
</div>
<div id="billing_details">
h1 class="heading">Billing Details</h1>
<h3>Your Name/Organisation Name<span class="star_require">*</span>:</h3>
<div><input type="text" id="name" name="name" value="" required /></div>
<h3>Your Area PIN code <span class="star_require">*</span>: </h3>
<div><input type="text" id="pincode" name="pincode" value="" maxlength="10" required /></div>
<div><input class="form_btn" type="submit" id="submit" value="submit" /></div>
</div>
</form>
</div>
<?php endwhile; ?>
</div>
<?php get_footer();
/*contact form.js*/
// JavaScript Document
$(document).ready(function(){
$("#key_val").hide();
$("div#ex_data").hide();
$("div#after_check").hide();
$no = $("#licenses").val();
$("#licenses").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
$("#course_master").change(function(){
var cid = $(this).val();
if(cid == 2)
{
$("#key_val").show();
$('#licenses').attr('disabled', 'disabled');
$("div#ex_data").css("display","none");
}
else{
$("#key_val").hide();
$("div#ex_data").show(1000);
$("#licenses").removeAttr("disabled");
}
$.ajax({
type:"POST",
url:"get_course_details.php",
data:"cid="+cid,
success:function(msg)
{
$("#course_details").html(msg);
}
});
});
$("#course_details").change(function(){
var id = $(this).val();
$.ajax({
type:"POST",
url:"get_course_info.php",
data:"id="+id,
success:function(msg)
{
$("#hidden_subtotal").val(msg);
if($no == '')
{
var total = msg * 1;
$("#sub_total").text(total);
}
else
{
var total = msg * $no;
$("#sub_total").text(total);
}
}
});
});
$("#check").click(function(){
if($(this).is(":checked")){
$("div#after_check").show(1000);
$("div#after_check #address").attr("required","true");
$("div#after_check h3").append("<span class='star_require'>*</span>");
}
else
{
$("div#after_check").hide(1000);
$("div#after_check #address").attr("required","false");
}
});
$("#key").blur(function(){
var key = $("#key").val();
$.ajax({
type:"POST",
url:"validate_key.php",
data:"key="+key,
success:function(msg)
{
if(msg ==1)
{
$("#licenses").removeAttr("disabled");
}
else
{
$('#licenses').attr('disabled', 'disabled');
}
}
});
});
$("#licenses").blur(function(){
var subtotal = $("#hidden_subtotal").val();
if(!isNaN(subtotal) && subtotal != '' && subtotal != 0)
{
subtotal = subtotal * $("#licenses").val();
$("#sub_total").text(subtotal);
}
});
$("#continue_first").click(function(){
$("div#contact_details").css("display","block");
});
$("#continue").click(function(){
$("div#billing_details").css("display","block");
});
$("#submit").click(function(){
var email = $("#email").val();
var mobile = $("#mobile").val();
var pincode = $("#pincode").val();
if( !isValidEmailAddress( email ) ) {
alert("invalid email address!"); return false;
}
else if(isNaN(mobile) || (mobile.length < 10) )
{
alert("invalid mobile no!"); return false;
}
else if(isNaN(pincode))
{
alert("Invalid Pincode!");return false;
}
else{
alert("success");
$( "#course_information" ).submit();
return true;
}
});
});
//if( !isValidEmailAddress( emailaddress ) ) { /* do stuff here */ }
function isValidEmailAddress(emailAddress) {
var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")#(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
return pattern.test(emailAddress);
};
Firstly for integrating from in wordpress you don't need to create config file and include. Just create template in theme which you are using and create page in wordpress admin and call this template.
I have my html page where people can sign up, which calls my php page for checks and inputs to db,
If i get an error, for example someone does not select their gender it alerts the user as it should. Problem is if the user does not select there gender and submits again the ajax is called twice now and i get two of the same alert messages, If done once more i get three alert messages and this contiunes growing on every press etc. How can i stop this happening.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>
</title>
<link rel="stylesheet" href="css/logout-button.min.css" />
<link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script src="js/jquery.cookies.2.2.0.min.js"></script>
<script src="js/account-login.js"></script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="account-signup">
<script>
function submitForm() {
$(document).ready(function() {
$("form#signupForm").submit(function() {
var form_data = $('#signupForm').serialize();
$.ajax({
type: "POST",
url: "ajaxResponder.php",
dataType: 'html',
data: form_data,
complete: function(data){
if(data.responseText == 'yes'){
alert("Your Account has been created");
$.mobile.changePage( "account-login.html", { transition: "slide"} );
}else {
alert(data.responseText);
}
}
});
return false;
});
});
}
</script>
<div data-theme="a" data-role="header">
<a data-role="button" href="account-login.html" data-transition="slide"
data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
Back
</a>
<h3>
Sign-Up
</h3>
</div>
<div data-role="content">
<form id="signupForm" name="signupForm">
<input name="method" id="method" placeholder="method" value="account-signup" type="hidden" />
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="forename">
Forename *
</label>
<input name="forename" id="forename" placeholder="Forename" value="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="surname">
Surname *
</label>
<input name="surname" id="surname" placeholder="Surname" value="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<label for="gender">Gender</label>
<select name="gender" id="gender" data-native-menu="false">
<option>Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div data-role="fieldcontain">
<script type="text/javascript">
$(function(){
var items="";
$.getJSON("ajaxResponder.php?method=account-signup-countries",function(data){
items+='<option value="Select Country">Select Country</option>';
$.each(data,function(index,item)
{
items+="<option value='"+item.id+"'>"+item.name+"</option>";
});
$("#countries").html(items);
$("#countries").trigger("change");
});
});
</script>
<legend>Country *</legend>
<select name="countries" id="countries" data-native-menu="false">
</select>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="email">
Email *
</label>
<input name="email" id="email" placeholder="Email" value="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="password">
Password *
</label>
<input name="password" id="password" placeholder="Password" value="" type="password" />
<label for="confirm">
Confirm Password *
</label>
<input name="confirm" id="confirm" placeholder="Confirm" value="" type="password" />
</fieldset>
</div>
<input data-theme="b" value="Sign-Up" type="submit" onclick="submitForm()" />
</form>
</div>
</div>
</body>
</html>
my php
case 'account-signup':
$password_minlength = 6;
$password_maxlength = 40;
$message == "";
function validusername($username) {
$allowedchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'";
for ($i = 0; $i < strlen($username); ++$i)
if (strpos($allowedchars, $username[$i]) === false)
return false;
return true;
}
$forename= $_POST["forename"];
$surname= $_POST["surname"];
$email= $_POST["email"];
$password= $_POST["password"];
$confirm= $_POST["confirm"];
$day = $_POST["select-choice-day"];
$month = $_POST["select-choice-month"];
$year = $_POST["select-choice-year"];
$country = $_POST["countries"];
$gender = $_POST["gender"];
if ($day =='Day' or $month == 'Mon' or $year =='Year')
$message = "You Need to fill in Your DOB";
if ($gender =='Gender')
$message ="Please select your Gender";
if ($country == "Select Country")
$message ="Please select a Country";
if (empty($password) || empty($forename) || empty($surname) || empty($email) || empty($confirm) )
$message = "All fields required to be filled in";
elseif ($password != $confirm)
$message = "Your passwords do not match";
elseif (strlen($password) < $password_minlength)
$message = sprintf("Your password needs to be more than $password_minlength char");
elseif (strlen($password) > $password_maxlength)
$message = sprintf("Your password needs to be less than $password_maxlength char");
elseif (!validusername($forename))
$message = "Invalid characters used in your forename";
elseif (!validusername($surname))
$message = "Invalid characters used in your surname";
elseif (!validemail($email))
$message = "A Valid email address is required";
if ($message == "") {
// check if email addy is already in use
$a = (#mysql_fetch_row(#SQL_Query_exec("select count(*) from users where email='$email'")));
if ($a[0] != 0)
$message = "Email Address $email has already signed up. Please use account-recovery ";
}
if ($message == "") {
$signupclass = '1';
$status = "confirmed";
$dob = "$year-$month-$day";
$secret = mksecret(); //generate secret field
$password = passhash($password);// hash the password
$forename1 = str_replace('\' ', '\'', ucwords(str_replace('\'', '\' ', strtolower($forename))));
$surname1 = str_replace('\' ', '\'', ucwords(str_replace('\'', '\' ', strtolower($surname))));
SQL_Query_exec("INSERT INTO users (forename,surname, password, secret, email, status, added, last_access, country, gender,dob, stylesheet, language, class, ip) VALUES (" .
implode(",", array_map("sqlesc", array($forename1,$surname1, $password, $secret, $email, $status, get_date_time(), get_date_time(), $country, $gender,$dob, $site_config["default_theme"], $site_config["default_language"], $signupclass, getip()))).")");
$message="yes";
}
echo "$message";
break;
You have an error in your javascript, when calling function, you don't need these lines:
$(document).ready(function() {
$("form#signupForm").submit(function() {
First of all you dont need document ready because you are not waiting for that state. Second thing, if you are using inline hjavascript with onclick=... you dont need to bind a submit event to the form.
Basically each time you call in again you are binding submit event to the form.
Third thing, this would not happen if validation was implemented on a client side, so think about that. You can easily implement jQuery Validate plugin.
My advice to you would be, remove onclick event from this line:
<input data-theme="b" value="Sign-Up" type="submit" onclick="submitForm()" />
Remove onclick function and just use everything like this:
$(document).ready(function() {
$('#signupForm').off('submit').on('submit',function(e) {
var form_data = $('#signupForm').serialize();
$.ajax({
type: "POST",
url: "ajaxResponder.php",
dataType: 'html',
data: form_data,
complete: function(data){
if(data.responseText == 'yes'){
alert("Your Account has been created");
$.mobile.changePage( "account-login.html", { transition: "slide"} );
}else {
alert(data.responseText);
}
}
});
return false;
});
});
Because of submit event this code will trigger when you press submit button, no need for onclick. And notice how submit is handled now:
$('#signupForm').off('submit').on('submit',function(e) {
This will prevent multiple submit events from happening.
Hi really need some help...
First of all I know very little of jQuery / javascript, I learnt basic CSS a month back after having a website professionally built, then basic HTML, a few days ago I thought I would try my luck with jQuery but I am a total novis so if you answer please keep in mind I know almost nothing about these things - thanks!
I have been trying to make a new contact form, I have used bits of code from all over the net (so I know the code is probably very messy) anyway the resulting form seems to work fine in Chrome but in IE or FF or Safari on the submit it returns the 'Sorry, there has been a problem with this form' alert and nothing happens, I guess the PHP script is returning '1' to make this happen, but to be honest I am in over my head!
Below is the jquery....
$(function(){
//original field values
var field_values = {
//id : value
'firstname' : 'first name',
'lastname' : 'last name',
'email' : 'email address',
'phone' : 'phone number',
};
//inputfocus
$('input#lastname').inputfocus({ value: field_values['lastname'] });
$('input#firstname').inputfocus({ value: field_values['firstname'] });
$('input#email').inputfocus({ value: field_values['email'] });
$('input#phone').inputfocus({ value: field_values['phone'] });
//reset progress bar
$('#progress').css('width','0');
$('#progress_text').html('0% Complete');
//second_step
$('form').submit(function(){ return false; });
$('#submit_second').click(function(){
//remove classes
$('#second_step input').removeClass('error').removeClass('valid');
var emailPattern = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var fields = $('#second_step input[type=text]');
var error = 0;
fields.each(function(){
var value = $(this).val();
if( value.length<1 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='email' && !emailPattern.test(value) ) ) {
$(this).addClass('error');
$(this).effect("shake", { times:3 }, 50);
error++;
} else {
$(this).addClass('valid');
}
});
if(!error) {
//update progress bar
$('#progress_text').html('66% Complete');
$('#progress').css('width','226px');
//slide steps
$('#second_step').slideUp();
$('#third_step').slideDown();
} else return false;
});
$('#submit_third').click(function(){
//update progress bar
$('#progress_text').html('100% Complete');
$('#progress').css('width','339px');
//prepare the fourth step
var fields = new Array(
$('#firstname').val() + ' ' + $('#lastname').val(),
$('#email').val(),
$('#phone').val(),
$('#service').val(),
$('#location').val(),
$('#mirror').val(),
$('#from').val()
);
var tr = $('#fourth_step tr');
tr.each(function(){
//alert( fields[$(this).index()] )
$(this).children('td:nth-child(2)').html(fields[$(this).index()]);
});
//slide steps
$('#third_step').slideUp();
$('#fourth_step').slideDown();
});
$('#submit_fourth').click(function(){
//Get the data from all the fields
var firstname = $('input[name=firstname]');
var email = $('input[name=email]');
var lastname = $('input[name=lastname]');
var phone = $('input[name=phone]');
//organize the data properly
var data = 'firstname=' + firstname.val() + '&email=' + email.val() + '&lastname=' + lastname.val() + '&phone=' + phone.val() + '&service=' + $('select#service option:selected').val() + '&location=' + $('select#location option:selected').val() + '&mirror=' + $('select#mirror option:selected').val() + '&leadfrom=' + $('select#from option:selected').val();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.summary').fadeOut('slow');
//show the success message
$('.success').fadeIn('slow');
$('#submit_fourth').attr("disabled", true);
window.location = "http://www.stackoverflow.com";
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, there has been a problem with this form. Thank you');
}
});
//cancel the submit button default behaviours
return false;
});
//back button
$('.back').click(function(){
var container = $(this).parent('div'),
previous = container.prev();
switch(previous.attr('id')) {
case 'first_step' : $('#progress_text').html('0% Complete');
$('#progress').css('width','0px');
break;
case 'second_step': $('#progress_text').html('33% Complete');
$('#progress').css('width','113px');
break;
case 'third_step' : $('#progress_text').html('66% Complete');
$('#progress').css('width','226px');
break;
default: break;
}
$(container).slideUp();
$(previous).slideDown();
});
});
and the HTML...
<div class="outer-formbody">
<div class="formbody">
Close
<div id="container">
<form action="#" method="post">
<!-- #second_step -->
<div id="second_step">
<h3>Book your appointment</h3>
<div class="form">
<input type="text" name="firstname" id="firstname" value="first name" />
<label for="firstname">Your First Name.<span>*</span></label><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="lastname" id="lastname" value="last name" />
<label for="lastname">Your Last Name.<span>*</span></label><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="email" id="email" value="email address" />
<label for="email">Your email address (not shared).<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="phone" id="phone" value="phone number" />
<label for="email">Your contact number (not shared).<span>*</span></label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_second" id="submit_second" value="" />
</div>
<!-- #third_step -->
<div id="third_step">
<h3>Book your appointment</h3>
<div class="form">
<select id="service" name="service" class="required">
<option value="">Please Select</option>
<option>Power of Attorney</option>
<option>Property Trust</option>
<option>Disabled Trust</option>
<option>Discretionary Trust</option>
<option>Other Trust</option>
<option>Protection / Insurance</option>
<option>Other Service</option>
</select>
<label for="service">Select the service you require.<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="location" name="location" class="required">
<option value="">Please Select</option>
<option>Staffordshire</option>
<option>Shropshire</option>
<option>West Midlands</option>
<option>Shropshire</option>
<option>Leicestershire</option>
<option>Birmingham</option>
<option>Cheshire</option>
<option>Other</option>
</select>
<label for="location">Select your home county.<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="mirror" name="mirror" class="required">
<option value="">Please Select</option>
<option>Single</option>
<option>Couple</option>
</select>
<label for="country">Single or two documents (for a couple).<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="from" name="from" class="required">
<option value="">Please Select</option>
<option>NHS/School/Council</option>
<option>Friend/Family Member</option>
<option>Other Public Sector Employer</option>
<option>Private Sector Employer</option>
<option>Internet Advert</option>
<option>Google</option>
<option>Newspaper</option>
<option>NetMums</option>
<option>MumsNet</option>
<option>Other</option>
</select>
<label for="from">Where did you hear about us?<span>*</span></label>
</div><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="back" type="button" value="" />
<input class="submit" type="submit" name="submit_third" id="submit_third" value="" />
</div>
<!-- #fourth_step -->
<div id="fourth_step">
<h3>Book your appointment</h3>
<div class="form">
<div class="success">
</br>
</br>
</br>
</br>
</br>
<h3>Booking Submitted. <span>Please Wait . . .</span></h3>
</div>
<div class="summary">
<h3>Summary</h3>
<table class="table">
<tr><td>Name</td><td></td></tr>
<tr><td>Email</td><td></td></tr>
<tr><td>Phone</td><td></td></tr>
<tr><td>Service</td><td></td></tr>
<tr><td>Location</td><td></td></tr>
<tr><td>Single/Couple</td><td></td></tr>
<tr><td>From</td><td></td></tr>
</table>
</div>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="back" type="button" value="" />
<input class="send submit" type="submit" name="submit_fourth" id="submit_fourth"value="" />
</div>
</form>
</div>
<div id="progress_bar">
<div id="progress"></div>
<div id="progress_text">0% Complete</div>
</div>
<div></div>
</div></div>
</div>
and the PHP script to process the form....
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$firstname = ($_GET['firstname']) ? $_GET['firstname'] : $_POST['firstname'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$lastname = ($_GET['lastname']) ?$_GET['lastname'] : $_POST['lastname'];
$phone = ($_GET['phone']) ?$_GET['phone'] : $_POST['phone'];
$service = ($_GET['service']) ?$_GET['service'] : $_POST['service'];
$location = ($_GET['location']) ?$_GET['location'] : $_POST['location'];
$mirror = ($_GET['mirror']) ?$_GET['mirror'] : $_POST['mirror'];
$leadfrom = ($_GET['leadfrom']) ?$_GET['leadfrom'] : $_POST['leadfrom'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//if the errors array is empty, send the mail
if (!$errors) {
//recipient
$to = 'Alex <clansey2004#yahoo.co.uk>';
//sender
$from = $firstname . ' <' . $email . '>';
//subject and the html message
$subject = 'Lead from ' . $firstname;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
</Br>
<table>
<tr><td>First Name</td><td>' . $firstname . '</td></tr>
<tr><td>Lastname</td><td>' . $lastname . '</td></tr>
<tr><td>Location</td><td>' . $location . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Phone</td><td>' . $phone . '</td></tr>
<tr><td>Service</td><td>' . $service . '</td></tr>
<tr><td>Mirror</td><td>' . $mirror . '</td></tr>
<tr><td>Lead From</td><td>' . $leadfrom . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
I am sure I have made a silly mistake - any help would be greatly appreciated!!
Thanks
My guess is you need to urlescape the values with encodeURIComponent(), especially those with a slash inside.