Ajax response is getting but not posting on the PHP page - php

I want to retrive the data got from jquery to php via ajax.
My code to start up a modal window
<a href='javascript:void(0):' data-id={$row['customer_id']} class='btn small bg-blue-alt tooltip-button modal-customeredit' data-placement='top' title='Edit'><i class='glyph-icon icon-edit' ></i>
here am getting id from main page.and opening a modal pop up.
modal script as follows.
$( ".modal-customeredit" ).click(function() {
var myGroupId = $(this).attr('data-id'); // data-id
data = {'id':myGroupId };
$.ajax({
type: "POST",
url: "left.inc.php",
data: data, // data retrieve on server-side ($_POST['id'])
success:function(response){
$( "#modal-customeredit" ).dialog({
modal: true,
minWidth: 700,
minHeight: 200,
dialogClass: "modal-dialog",
show: "fadeIn"
});
alert('done');
alert(response); //do the rest of operations.
}
});
my form code is for modal:
<!-- Customer Edit -->
<div class="hide" id="modal-customeredit" title="Edit Customer Info">
<div class="pad10A">
<h3>Update Customer Info</h3>
<p class="font-gray-dark"> Fides Admin uses colors & styles from both the default theme color schemes and the included core color helpers. </p>
<div class="divider"></div>
<form id="customer-edit" action="" class="col-md-12 center-margin" method="">
<div class="form-row">
<div class="form-label col-md-3">
<label for="name">
Name:
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="name" name="name" placeholder="Name" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="details">
Details :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="details" placeholder="Details" name="details" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="domain">
Domain :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="domain" placeholder="Domain" name="domain" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="vertical">
Vertical :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="vertical" placeholder="Vertical" name="vertical" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="taxanomy">
Taxanomy :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="taxanomy" placeholder="Taxanomy" name="taxanomy" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="divider"></div>
<div class="form-row">
<div class="form-input col-md-8 col-md-offset-3">
<span class="button-content">Submit</span>
</div>
</div>
</form>
</div>
</div>
<?php } elseif ($pfile=="customer-screen.php") { ?>
The problem i face is i got response from ajax.which display the exact id i want.
But when i try in php as
<?php $id=$_POST['id'];
echo $id; ?>
I was not able to echo the id in php file.But ajax display in the response.Hope i am conveying the question properly.If u help it will be really appreciated.If you have doubts about my question.Please comment let me expalin.

The data you're posting is in JSON format, not URL format. The data should be 'id=' + myGroupId.

Related

multipage form with jquery and php validation

I am working with a multipage form, needs to validate in each page. jquery validating well, but i have to post the data in the same page through ajax to backend for php validation and if return success needs to load the next page or else need to show validation error from backend to front end.
The problem is, here the form is getting validated well in frontend but not posting data for backend validation what i am doing wrong in the code please advice. Thanks in advance
HTML
<form class="ui form segment" id="msform" action="main.php" method="post">
<ul id="progressbar">
<li class="active">Account Setup</li>
<li>Career Details</li>
<li>Personal Details</li>
</ul>
<fieldset class="step">
<div class="two fields">
<div class="field">
<label>First name</label>
<input placeholder="First Name" name="first_name" type="text">
</div>
<div class="field">
<label>Last name</label>
<input placeholder="Last Name" name="last_name" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Display name</label>
<input placeholder="Display Name" name="display_name" type="text">
</div>
<div class="field">
<label>User name</label>
<input placeholder="User Name" name="user_name" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Email</label>
<input placeholder="Email" name="email" type="text">
</div>
<div class="field">
<label>Password</label>
<input type="password" placeholder="Password" name="password" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Date of birth</label>
<div class="ui calendar" id="date_birth">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" placeholder="Date" name="dob">
</div>
</div>
</div>
<div class="field">
<label>Gender</label>
<div class="ui selection dropdown">
<input name="gender" type="hidden">
<div class="default text">Gender</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="1">Male</div>
<div class="item" data-value="0">Female</div>
</div>
</div>
</div>
</div>
<div class="field">
<label>Marital status</label>
<div class="ui selection dropdown">
<input name="marital_status" type="hidden">
<div class="default text">Marital status</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="married">Married</div>
<div class="item" data-value="single">Single</div>
</div>
</div>
</div>
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset class="step">
<div class="two fields">
<div class="field">
<label>Highest qualification</label>
<input placeholder="Highest qualification" name="highest_qualification" type="text">
</div>
<div class="field">
<label>University/college</label>
<input placeholder="University/college" name="university_or_college" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Course type</label>
<div class="ui selection dropdown">
<input name="course_type" type="hidden">
<div class="default text">Course type</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="1">Full time</div>
<div class="item" data-value="0">Part time</div>
</div>
</div>
</div>
<div class="field">
<label>Mobile</label>
<input placeholder="Mobile" name="mobile" type="text">
</div>
</div>
<div class="field" id="container">
<label>Upload resume</label>
<label for="file" class="ui icon button">
<i class="file icon"></i>
<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<a id="pickfiles" href="javascript:;">Select resume</a> <br />
</label>
<input type="file" id="file" style="display:none">
<a id="uploadfiles" href="javascript:;">Upload</a>
</div>
<div class="field" id="container">
<label>Upload photo</label>
<label for="file" class="ui icon button">
<i class="file icon"></i>
<div id="filelist_new">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<a id="pickfiles_new" href="javascript:;">Select photo</a>
</label>
<a id="uploadfiles_new" href="javascript:;">Upload</a>
<input type="file" id="file" style="display:none">
</div>
<div class="two fields">
<div class="field">
<label>Current designation</label>
<input placeholder="Current designation" name="current_designation" type="text">
</div>
<div class="field">
<label>Current company</label>
<input placeholder="Current company" name="current_company" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Annual salary</label>
<div class="ui selection dropdown">
<input name="annual_salary" type="hidden">
<div class="default text">annual_salary</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="0">Less than 1 Lakh</div>
<div class="item" data-value="1">1 to 2 Lakh</div>
<div class="item" data-value="2">2 to 3 Lakh</div>
<div class="item" data-value="3">3 to 4 Lakh</div>
<div class="item" data-value="4">5 Lakh and above </div>
</div>
</div>
</div>
<div class="field">
<label>Working since</label>
<div class="ui calendar" id="date_work">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input placeholder="Working since" name="working_since" type="text">
</div>
</div>
</div>
</div>
<div class="two fields">
<div class="field">
<label>Current location</label>
<input placeholder="Current location" name="current_location" type="text">
</div>
<div class="field">
<label>Duration of notice</label>
<div class="ui selection dropdown">
<input name="duration_of_notice" type="hidden">
<div class="default text">Duration of notice</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="0">Less than 15 days</div>
<div class="item" data-value="1">15 days to 1 month</div>
<div class="item" data-value="2">1 to 2 month</div>
</div>
</div>
</div>
</div>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset class="step">
<div class="two fields">
<div class="field">
<label>Skills</label>
<input placeholder="Skills" name="skills" type="text">
</div>
<div class="field">
<label>Passing year</label>
<div class="ui calendar" id="example8">
<div class="ui input left icon">
<i class="time icon"></i>
<input type="text" name="passing_year" placeholder="Year">
</div>
</div>
</div>
</div>
<div class="two fields">
<div class="field">
<label> Present address</label>
<input placeholder="Present address" name="address_1" type="text">
</div>
<div class="field">
<label> Permanent address</label>
<input placeholder="Permanent address" name="address_2" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>City</label>
<input placeholder="City" name="city" type="text">
</div>
<div class="field">
<label>State</label>
<input placeholder="State" name="state" type="text">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Country</label>
<input placeholder="Country" name="country" type="text">
</div>
<div class="field">
<label>Certifications</label>
<input placeholder="Certifications" name="certifications" type="text">
</div>
</div>
<div class="field">
<label>Will relocate </label>
<div class="ui selection dropdown">
<input name="will_relocate" type="hidden">
<div class="default text">Will relocate</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="0">Yes</div>
<div class="item" data-value="1">No</div>
</div>
</div>
</div>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" class="submit action-button" value="Submit" />
</fieldset>
</form>
jQuery
$(document).ready(function(){
var current = 1;
widget = $(".step");
btnnext = $(".next");
btnback = $(".previous");
btnsubmit = $(".submit");
// Init buttons and UI
widget.not(':eq(0)').hide();
hideButtons(current);
setProgress(current);
// Next button click action
btnnext.click(function(){
current_fs = $(this).parents();
next_fs = $(this).parent().widget;
if(current < widget.length){
// Check validation
if($(".form").valid()){
dataString = [];
$('#msform').ajaxForm({
type: "POST",
url: "main.php",
data:{data: $(dataString).serializeArray()},
dataType: "json",
cache: false,
});
widget.show();
$("#progressbar li").eq($("fieldset").index(setProgress(current))).addClass("active");
widget.not(':eq('+(current++)+')').hide();
setProgress(current);
}
}
hideButtons(current);
})
// Back button click action
btnback.click(function(){
current_fs = $(this).parent();
previous_fs = $(this).parent().btnback;
if(current > 1){
current = current - 2;
if(current < widget.length){
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
widget.show();
widget.not(':eq('+(current++)+')').hide();
setProgress(current);
}
}
hideButtons(current);
})
// Submit button click
btnsubmit.click(function(){
dataString = [];
$('#msform').ajaxForm({
type: "POST",
url: "main.php",
data:{data: $(dataString).serializeArray()},
dataType: "json",
cache: false,
success: function(){
alert("You have submitted form successfully");
// $("form")[0].reset();
}
});
});
$('#msform').validate({ // initialize plugin
ignore:":not(:visible)",
rules: {
first_name : { required: true, minlength: 3},
last_name : "required",
display_name : { required: true, minlength: 3},
user_name : { required: true, minlength: 3},
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
dob : {
required: true,
},
gender : "required",
marital_status: "required",
highest_qualification:"required",
university_or_college: "required",
mobile:{
required:true,
minlength:10,
maxlength:10,
number: true
},
current_designation:"required",
current_company:"required",
annual_salary:"required",
working_since:"required",
current_location:"required",
duration_of_notice:"required",
skills:"required",
address_1:"required",
city:"required",
state:"required",
country:"required",
certifications:"required",
},
});
});
// Change progress bar action
setProgress = function(currstep){
current_fs = $(this).parent();
next_fs = $(this).parent().btnnext;
var percent = parseFloat(100 / widget.length) * currstep;
percent = percent.toFixed();
$(".progress-bar").css("width",percent+"%").html(percent+"%");
$("#progressbar li").eq($(".step").index(current_fs)).removeClass("active");
}
// Hide buttons according to the current step
hideButtons = function(current){
var limit = parseInt(widget.length);
$(".action").hide();
if(current < limit) btnnext.show();
if(current > 1) btnback.show();
if (current == limit) {
btnnext.hide();
btnsubmit.show();
}
}
PHP
$post_data = $_POST;
print_r($post_data);

php not receives data from ajax FormData

I'm trying to send multiple data and files by jquery ajax (using formData) to a php file but i don't recive anything in the php file neither $_POST nor $_FILE data, I receive NULL in both.
Here is my ajax function.
$('#formulario').submit(function(e){
e.preventDefault();
$.ajax({
url:"../phpfile.php",
type:"POST",
dataType:"JSON",
data: new FormData(this),
processData: false,
contentType: false
}).always(function(respuesta){
//code
});
});
Here is my HTML
<form enctype="multipart/form-data" method="POST">
<div class='row'>
<div class='col-xs-12'>
<h4>Destinatarios</h4>
<select class='form-control' required name='destinatarios[]' title='Selecciona cuantos quieras' multiple data-selected-text-format="count>2" data-live-search="true">
{%for familiar in familia%}
<option value='{{familiar.ID_PERSONA}}'>{{familiar.NOMBRE}} {{familiar.APELLIDOS}}</option>
{%endfor%}
</select>
</div>
<div class='col-xs-6 hidden'>
<h4>Tipo de entrega</h4>
<select class='form-control' id='entrega' name='entrega'>
<option value='1' selected></option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class='col-xs-4 text-center'>
<h4>Despues de mi partida</h4>
<input type="radio" value="muerte" name="tipoE" onchange="cambioR(this)">
</div>
<div class='col-xs-4 text-center'>
<h4>En fecha determinada</h4>
<input type="radio" value="fecha" name="tipoE" onchange="cambioR(this)">
</div>
<div class='col-xs-4 text-center'>
<h4>En mi ceremonia de despedida</h4>
<input type="radio" value="ceremonia" name="tipoE" onchange="cambioR(this)">
</div>
</div>
<br>
<div class="row">
<div id="f" class="hidden">
<div class="col-xs-12">
<div class="input-group date" id="sandbox-container">
<span class="input-group-addon">Fecha</span>
<input type="text" class="form-control date" placeholder="dd/mm/yyyy" name="fecha" id="fecha">
</div>
<br>
</div>
</div>
<div id="m" class="hidden">
<div class="col-xs-12">
<div class="input-group">
<span class="input-group-addon">Días después de mi partida</span>
<input class="form-control" id="muerte" name="muerte">
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h4>Mensaje</h4>
<input class="hidden" id="nombre_mensaje" name="nombre_mensaje">
<textarea class="form-control" rows="10" style="resize: none" id='mensaje' name='mensaje' required></textarea>
<br>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h4>Imágenes / Video / Audio / Archivos</h4>
<div class="grid" id="muestras" dc>
<div class="grid-item col-xs-3 deseo" onclick="novoFile(this);">
<img src="../Recursos/imagenes/plus.jpg" width="100%;">
<input class="hidden" type="file" onchange="cambio(this);" name="files[]">
<input class="hidden datas" name="data_multimedia[]" value="0">
</div>
</div>
</div>
</div>
<input class="hidden" id="id_mensaje" name="id_mensaje">
<input type="reset" id="reiniciar" hidden>
</form>
The user can upload as many files as he want, and the html input file is added dinamicly using jquery.
Try to replace:
new FormData(this);
with:
$('#formulario').serialize();

email successfully sent to my email account but browser freezes at sendemail.php page [duplicate]

This question already has answers here:
send email through php
(2 answers)
Closed 6 years ago.
I get the email as i set to my code , but when the script executed , browser redirects me to sendemail.php and freezes there.
here is the screenshot
sendemail.php
here is the code for FORM element to my html file
</section> -->
<section id="contact">
<div id="contact-us" class="parallax">
<div class="container">
<div class="row">
<div class="heading text-center col-sm-8 col-sm-offset-2 wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<h2>Contact Us</h2>
<p>Request a service , learn about our services</p>
</div>
</div>
<div class="contact-form wow fadeIn" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="row">
<div class="col-sm-6">
<form id="contact-form" name="contact-form" method="post" enctype="application/x-www-form-urlencoded" action="sendemail.php">
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms" id="message_form">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Subject" required="required">
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit" name="submit" id="submit">Send Now</button>
</div>
</form>
</div>
<div class="col-sm-6">
<div class="contact-info wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<p></p>
<ul class="address">
<li><i class="fa fa-phone"></i> <span> Phone:</span> my phone </li>
<li><i class="fa fa-envelope"></i> <span> Email:</span> info#mydomain.com</li>
<li><i class="fa fa-globe"></i> <span> Website:</span> www.mydomain.com</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section><!--/#contact-->
And here is the script that calls sendemail.php
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function(e) {
var data = name : $("#name").val(),
subject:$("#subject").val ,
email: $("#email").val(),
message: $("#message").val()};
console.log(data);
$.ajax({
type: "post",
url: "sendemail.php",
data: data,
success: function(){
alert("it was success");
}
});
</script>
<!-- begin snippet: js hide: false console: true babel: false -->
here is the code for sendemail.php
<?php
$msg = 'Name: ' .$_POST['name'] ."\n"
.'Email :' .$_POST['email'] ."\n"
.'Subject: ' .$_POST['subject'] ."\n"
.'Message: ' .$_POST['message'] ."\n";
mail('info#mydomain.com','You have one message from santoriginal.com', $msg); ?>
WHere is the wrong to my code ?
Thanks
Your browser doesn't freeze, sendemail.php has no content.
An AJAX call to sendemail.php will not redirect you to sendemail.php, but your form does.
Try using return false; in the $('#submit').click(); this way the form is not submitted.

how will i passed the json data into php

I have four textboxes and when you click on the add one button it will add up another set of textboxes. My problem is how can i pass the json data to the action form. Here is my code:
$("#test").click(function(){
var array = $('.experience').map(function() {
var obj = {};
$(this).next().addBack().find('input:text').each(function() {
obj[this.id] = this.value;
});
return obj;
}).get();
$('#json').text(JSON.stringify(array, null, 2));
});
and my form action
<form action="<?php echo base_url().'resume/update'?>" method="post" id="send_form">
<!-- Experience Start -->
<div class="row">
<div class="col-sm-12">
<p> </p>
<h2>Experience</h2>
</div>
</div>
<div class="row experience">
<div class="col-sm-6">
<div class="form-group">
<label for="resume-employer">Employer</label>
<input type="text" class="form-control" name="resumeEmployer" id="resume-employer" value="<?php echo set_value('resumeEmployer'); ?>" id="resume-employer" placeholder="Company name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="resume-experience-dates">Start/End Date</label>
<input type="text" class="form-control" name="resumeExperienceDates" name="<?php echo set_value('resumeExperienceDates'); ?>" id="resume-experience-dates" placeholder="e.g. April 2010 - June 2013">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="resume-job-title">Job Title</label>
<input type="text" class="form-control" name="resumeJobTitle" id="resume-job-title" value="<?php echo set_value('resumeJobTitle'); ?>" placeholder="e.g. Web Designer">
</div>
</div>
<div class="col-sm-6">
<div class="form-group" id="resume-responsibilities-group">
<label for="resume-responsibilities">Responsibilities (Optional)</label>
<input type="text" class="form-control" name="resumeResponsibilities" id="resume-responsibilities" value="<?php echo set_value('resumeResponsibilities');?>" placeholder="e.g. Developing new websites">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr class="dashed">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p><a id="add-experience">+ Add Experience</a></p>
<hr>
</div>
</div>
<!-- Experience Start -->
<div class="row text-center">
<div class="col-sm-12">
<p> </p>
<input type="submit" id="test" class="btn btn-primary btn-lg" value="Submit" />
</div>
</div>
</form>
i added a id="test" in the input type="submit button
any help is muchly appreciated. TIA
Use json_encode and json_decode function example in ref link,
json_encode($arr);
var_dump(json_decode($json));
http://php.net/manual/en/function.json-encode.php
var_dump(json_decode($json, true));

Thank you message not showing when Ajax form goes through

I'm trying to hide the regular content and display a thank you message in it's place after a form is sent. However when the form sends, the fields reset but the thank you message won't appear. Please help. I'm not that great with jQuery.
I'm also using the foundation abide.js, don't know if that makes difference or not.
Here is the ajax code.
$(function() {
// Get the form.
var form = $('#form');
// Get the messages div.
var formMessages = $('#thanks');
// Set up an event listener for the contact form.
$(form).submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
var formData = $(form).serialize();
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
}).done(function(response) {
$('#thanks').show();
$(form).hide();
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#number').val('');
})
});
});
This is the code for the form.
<div class="newsletter" id="contact">
<div class="row footer-top">
<div class="large-12 medium-12 columns updates" id="thanks" style="display: none;">
<h4>Thanks! We'll be in touch shortly.</h4>
</div>
<div class=" large-12 medium-12 column updates" id="normal">
<h4>Want more info? Contact us!</h4>
<p>Sign up to stay in touch with what's happening. Don't Worry, we don't spam.</p>
</div>
</div>
<form data-abide id="form" method="post" action="wp-content/themes/myles_custom/mailer.php">
<div class="row">
<div class="large-8 large-centered columns">
<label>
Name:
<input type="text" name="name" id="name" placeholder="Name" value="<?php if(isset($name)){echo htmlspecialchars($name);} ?>" required pattern="[a-zA-Z]+">
</label>
<small class="error">Name is required.</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Email:
<input type="email" id="email" name="email" placeholder="Email" value="<?php if(isset($email)){echo htmlspecialchars($email);} ?>" required>
</label>
<small class="error">Email is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Number:
<input type="tel" pattern="number" id="number" name="number" placeholder="Name" value="<?php if(isset($number)){echo htmlspecialchars($number);} ?>" required>
</label>
<small class="error">Number is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Campus:
<select id="campus" name="campus">
<option>FSU</option>
<option>FAMU</option>
<option>TCC</option>
</select>
</label>
<small class="error">Campus is required</small>
</div>
</div>
<div id="sucks" style="display: none;">
<label for="address" id="adress_label" style: "display: none;">Address</label>
<input name="address" id="address" type="text" style="display: none;">
</div>
<div class="row">
<div class="large-12 columns" style="text-align: center;">
<button id="submit" type="submit" value="Send">Submit</button>
</div>
</div>
</form>
</div>
You have a extra closing bracket in the code, and I also would not use $(form) with jquery instead use an id reference $("#form").
I made a quick working example at https://jsfiddle.net/mum1m1sc/
$("#myForm").submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
var formData = $("#myForm").serialize();
$.ajax({
type: 'POST',
url: $("#myForm").attr('action'),
data: formData
}).done(function(response) {
$('#thanks').show();
$("#myForm").hide();
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#number').val('');
});
});
<div class="newsletter" id="contact">
<div class="row footer-top">
<div class="large-12 medium-12 columns updates" id="thanks" style="display: none;">
<h4>Thanks! We'll be in touch shortly.</h4>
</div>
<div class=" large-12 medium-12 column updates" id="normal">
<h4>Want more info? Contact us!</h4>
<p>Sign up to stay in touch with what's happening. Don't Worry, we don't spam.</p>
</div>
</div>
<form data-abide id="myForm" method="post" action="">
<div class="row">
<div class="large-8 large-centered columns">
<label>
Name:
<input type="text" name="name" id="name" placeholder="Name" value="" required pattern="[a-zA-Z]+">
</label>
<small class="error">Name is required.</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Email:
<input type="email" id="email" name="email" placeholder="Email" value="" required>
</label>
<small class="error">Email is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Number:
<input type="tel" id="number" name="number" placeholder="Name" value="">
</label>
<small class="error">Number is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Campus:
<select id="campus" name="campus">
<option>FSU</option>
<option>FAMU</option>
<option>TCC</option>
</select>
</label>
<small class="error">Campus is required</small>
</div>
</div>
<div id="sucks" style="display: none;">
<label for="address" id="adress_label" style: "display: none;">Address</label>
<input name="address" id="address" type="text" style="display: none;">
</div>
<div class="row">
<div class="large-12 columns" style="text-align: center;">
<button id="submit" type="submit" value="Send">Submit</button>
</div>
</div>
</form>
<div id="thanks" style="display:none;">
<h3>Thanks</h3>
</div>
hope that helps.

Categories