Two Forms In a HTML Document - php

I am having a form as below.
<div class="container">
<form method="post" action="index.php">
<div id="rule">
<div class="row">
<div class="span5">
<input type="text" class="input-xlarge" value="Rule Name"/>
</div>
<div class="span6">
<input type="text" class="input-xxlarge" value="Description"/>
</div>
<div class="clearfix"> </div>
</div>
</div>
<br />
<div id="sel" class="select">
<div class="row">
<div class="span1 offset2">
<p class="btn btn-danger">If</p>
</div>
<div class="span2">
<select class="span2" name="metrics">
<option value="bounce_rate">Bounce Rate</option>
<option value="location">Locations</option>
<option value="social_media">Social Media</option>
<option value="search">Search</option>
<option value="visits">Visitors</option>
</select>
</div>
<div class="span1">
<select name="conditions" class="span2">
<option value=">">></option>
<option value="<"><</option>
<option value=">=">>=</option>
<option value="<="><=</option>
<option value="=">=</option>
</select>
</div>
<div class="span1 offset1">
<input type="text" name="percentage" class="input-small"/>
</div>
<div class="clearfix"> </div>
</div>
<br />
<div class="row">
<div class="span1 offset2">
<p class="btn btn-danger">Period</p>
</div>
<div class="span3">
<div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
<input class="span2" size="16" type="text" value="12-02-2012" />
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="span3">
<div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
<input class="span2" size="16" type="text" value="12-02-2012" />
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>
<div id="dyna"></div>
<div id="end">
<div class="row">
<div class="span1">
<p class="btn btn-danger">THEN</p>
</div>
<div class="span3">
<input type="text" class="input-xlarge" value="Statement" />
</div>
<div class="clearfix"> </div>
</div>
<div class="row">
<div class="span1">
<p class="btn btn-danger">ELSE</p>
</div>
<div class="span3">
<input type="text" class="input-xlarge" value="Statement" />
</div>
<div class="clearfix"> </div>
</div>
<div class="row">
<button class="span1 btn btn-success" type="submit" value="submit">Submit</button>
<div class="span2 offset9">
<p class="btn btn-success input-small" id="addRule">Add Rule </p>
</div>
<div class="clearfix"> </div>
</div>
</div>
</form>
</div>
I have included a button 'Add Rule' to create a dynamic elements within the above . So I used a javascript for creating dynamic elements as same of above.
The javascript as below.
<script type="text/javascript">
$('.datepicker').datepicker();
(function(){
var i = 0;
$("#addRule").live('click',function(){
++i;
var $ctrl = $('<div id="'+ i +'" class="select"><div class="row"><div class="span1 offset2"><button class="btn btn-danger">If</button></div><div class="span2"><select class="span2" name="metrics"><option value="bounce_rate">Bounce Rate</option><option value="location">Locations</option><option value="social_media">Social Media</option><option value="search">Search</option><option value="visits">Visitors</option></select></div><div class="span1"><select name="conditions" class="span2"><option value=">">></option><option value="<"><</option><option value=">=">>=</option><option value="<="><=</option><option value="=">=</option></select></div><div class="span1 offset1"><input type="text" name="percentage" class="input-small"/></div><div class="span2 offset1"><button class="btn btn-danger remove" id="'+ i +'">Remove</button></div><div class="clearfix"> </div></div><br /><div class="row"><div class="span1 offset2"><p class="btn btn-danger">Period</p></div><div class="span3"><div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy"><input class="span2" size="16" type="text" value="12-02-2012" /><span class="add-on"><i class="icon-th"></i></span></div></div><div class="span3"><div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy"><input class="span2" size="16" type="text" value="12-02-2012" /><span class="add-on"><i class="icon-th"></i></span></div></div><div class="clearfix"> </div></div></div>');
$("#dyna").append($ctrl);
$('.datepicker').datepicker();
});
}) ();
(function(){
$(".remove").live('click',function(){
var remDiv = $(this).attr('id');
//var questionList = "questionList"+remQ;
$("#" + remDiv).remove();
});
}) ();
So I wanna get the values once i click the submit button. Is it correct way what i am using only a form for fetching the data or am i create two forms separately? So how to do that?

You do not need to create a second form if you are inserting the new elements into the existing form and as long as they have different names from any existing inputs you want to receive.
You can create a second form if you want different submit buttons for the two different collections of input data.

Related

How to make dynamic bootstrap modal work on Iphones?

There is problem in opening bootstrap modal in iphones.
If i use static modal like below,
<a href="#responsive" data-toggle="modal"><button class="btn btn-green ">Add Product<i class="fa fa-plus"></i></button>
</a>
<!-- start: BOOTSTRAP EXTENDED MODALS -->
<div id="responsive" class="modal extended-modal fade no-display">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×
</button>
<h4 class="modal-title" style="color:red">Add New Product</h4>
</div>
<div class="modal-body">
<div class="row">
<form name="new" action="<?php echo base_url() ?>admin/addProduct" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="col-md-6">
<h4><b>Category Name <span class="symbol required"></span></b></h4>
<p>
<select class="form-control" name="cat_id" required>
<option value="">---- Select Category ----</option>
<?php foreach($cat['list'] as $rows=>$value){ ?>
<option value="<?php echo $cat['list'][$rows]->cat_id; ?>"><?php echo ucwords($cat['list'][$rows]->cat_name); ?></option>
<?php } ?>
</select>
</p>
</div>
<div class="col-md-6">
<h4><b>Product Name <span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="item_name" required>
</p>
</div>
<div class="col-md-6">
<h4><b>Small Description <span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="small_desc">
</p>
</div>
<div class="col-md-6">
<h4><b>Quantity<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="number" name="quantity" required min="1">
</p>
</div>
<div class="col-md-6">
<h4><b>Customer Price<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="number" name="price" required min="1">
</p>
</div>
<div class="col-md-6">
<h4><b>Reseller Price<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="number" name="reseller" required min="1">
</p>
</div>
<div class="col-md-6">
<h4><b>Color<span class="symbol "></span></b></h4>
<p>
<input class="form-control" type="text" name="color">
</p>
</div>
<div class="col-md-6">
<h4><b>Availability <span class="symbol required"></span></b></h4>
<select class="form-control" name="availability">
<option value="1">Available</option>
<option value="0">Not Available</option>
</select>
</div>
<div class="col-md-6">
<h4><b>Image <span class="symbol required"></span></b></h4>
<p>
<input class="form-control" accept="image/*" onchange="loadFile(event)" type="file" name="userfile" required multiple>
<img id="output" width="100px" height="100px" />
</p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" data-dismiss="modal" class="btn btn-light-grey">
Close
</button>
<button type="submit" class="btn btn-blue">
Add Product
</button>
</div>
</form>
</div>
</div>
</div>
<!-- End Modal -->
the modal will open properly and i can enter values.
But if use the modal for editing like below,
<a href="#edit<?php echo $product['list'][$row]->item_id; ?>" data-toggle="modal">
<button class="btn btn-blue"><i class="fa fa-pencil"></i> Edit </button>
</a>
<div id="edit<?php echo $product['list'][$row]->item_id?>" class="modal extended-modal fade no-display">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×
</button>
<h4 class="modal-title" style="color:red">Edit Product</h4>
</div>
<div class="modal-body">
<div class="row">
<form action="<?php echo base_url() ?>admin/editProduct" enctype="multipart/form-data" method="post" autocomplete="off">
<div class="col-md-6">
<h4><b>Category Name <span class="symbol required"></span></b></h4>
<p>
<select class="form-control" name="cat_id" required>
<option value="">---- Select Category ----</option>
<?php
foreach($cat['list'] as $rows=>$value){ ?>
<option value="<?php echo $cat['list'][$rows]->cat_id; ?>"<?php if($cat['list'][$rows]->cat_id == $product['list'][$row]->cat_id) echo "selected=selected"; ?>><?php echo ucwords($cat['list'][$rows]->cat_name); ?></option>
<?php } ?>
</select>
</p>
</div>
<div class="col-md-6">
<input type="hidden" name="item_id" value="<?php echo $product['list'][$row]->item_id;?>">
<input type="hidden" name="image_name" value="<?php echo $product['list'][$row]->image;?>">
<h4><b>Product Name <span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="item_name" value="<?php echo $product['list'][$row]->item_name;?>" required>
</p>
</div>
<div class="col-md-6">
<h4><b>Small Description <span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="small_desc" value="<?php echo $product['list'][$row]->small_desc;?>">
</p>
</div>
<div class="col-md-6">
<h4><b>Quantity<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="number" name="quantity" value="<?php echo $product['list'][$row]->quantity;?>" min="1" required>
</p>
</div>
<div class="col-md-6">
<h4><b>Customer Price<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="price" value="<?php echo $product['list'][$row]->price;?>" min="1" required>
</p>
</div>
<div class="col-md-6">
<h4><b>Reseller Price<span class="symbol required"></span></b></h4>
<p>
<input class="form-control" type="text" name="reseller" value="<?php echo $product['list'][$row]->reseller;?>" min="1" required>
</p>
</div>
<div class="col-md-6">
<h4><b>Color<span class="symbol"></span></b></h4>
<p>
<input class="form-control" type="text" name="color" value="<?php echo $product['list'][$row]->color;?>">
</p>
</div>
<div class="col-md-6">
<h4><b>Availability <span class="symbol required"></span></b></h4>
<select class="form-control" name="availability">
<?php if($product['list'][$row]->availability==1){;?>
<option value="1" selected>Available</option>
<option value="0">Not Available</option>
<?php } else {?>
<option value="1">Available</option>
<option value="0" selected>Not Available</option>
<?php }?>
</select>
</div>
<div class="col-md-6">
<h4><b>Status <span class="symbol required"></span></b></h4>
<select class="form-control" name="status">
<?php if($product['list'][$row]->status==0){;?>
<option value="0" selected>Inactive</option>
<option value="1">Active</option>
<?php } else {?>
<option value="0">Inactive</option>
<option value="1" selected>Active</option>
<?php }?>
</select>
</div>
<div class="col-md-6">
<h4><b>Image <span class=""></span>
</b></h4>
<input class="form-control" type="file" name="userfile">
<img src="<?php echo base_url()." assets/uploads/ ".$product['list'][$row]->image;?>" height="50px" width="50px" border="1px solid #FFF">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-light-grey">
Close
</button>
<button type="submit" class="btn btn-blue">
Update
</button>
</div>
</form>
</div>
</div>
</div>
With dynamic id, the modal will open with light black overlay on it. I can't edit the fields. Nothing is working inside the modal.
I am Not Understanding What is the problem with dynamic modal.
If Anyone knows Please reply.
You can try two things. 1. Move your form tag out and place it like this -
<form action="./admin/editProduct" enctype="multipart/form-data" method="post" autocomplete="off">
<div class="modal-body">
Give your modal z-index of 999 or so using css like this -
<style>
.modal {
z-index: 999;
}
</style>

create a shortcode of html form

I am trying to create a short code for html form. because I want to use this multiple time in my word-press page.
I have no idea how to do this . if any help please let help me
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
<input type='hidden' name='page_id' value='2599'>
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>
Try this.
<?php
function my_shortcode(){
$pagelink = get_page_link(2599);
return '<form action="'.$pagelink.'" method="POST" >
<input type="hidden" name="page_id" value="2599">
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>';
}
add_shortcode('my_shortcode_name','my_shortcode');
?>
you can use this shortcode in your page
<?php echo do_shortcode('[my_shortcode_name]');?>
I think you are saying that you do not want to copy-paste the exact same code on multiple places inside your project, PHP has an include control structure method to take any file and use the contents on run-time.
Your code could eventually look something like this:
# form definition inside the main page that needs the form
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
# include the template
<?php include('template.php') ?>
</form>
# template.php contains the html form
<input type='hidden' name='page_id' value='2599'>

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);

Custom Signup Form Using Mailchimp - Connection could not be established with host mail.yourdomain.com [Operation timed out #60]

I am trying to have a custom form on my website. The form gathers diet preferences, and upon submit, I'd like to grab that information with their name and email, and add it to a list in Mailchimp. I have setup the list correctly in Mailchimp, and the form is built and styled on my page. I followed the following article, as you can see in my code, based on Mailchimp's recommendation on creating a custom form.
http://kb.mailchimp.com/lists/signup-forms/host-your-own-signup-forms
I think I have connected each input to it's corresponding element in the Mailchimp list, but when I hit the submit button, nothing happens for about 20 seconds and then I get the following error:
Connection could not be established with host mail.yourdomain.com [Operation timed out #60]
I am currently developing on a local server using MAMP - and feel this may be an issue, but if not what can I do to make this custom form work properly?
<form action="https://platesite.us14.list-manage.com/subscribe/post" method="POST" class="text-center form-email">
<input type="hidden" name="u" value="694035325d6c49e6922fda852">
<input type="hidden" name="id" value="e9b40e5d0e">
<h4 class="uppercase mt48 mt-xs-0">Tell Us about yourself</h4>
<p class="lead mb64 mb-xs-24">
Share a little bit about your taste preferences <br>
so we can create a plan just for you.
</p>
<div class="overflow-hidden">
<hr>
<h6 class="uppercase">
1. What is your plan preference?
</h6>
<div class="col-sm-3">
<p class="mb16">
Simply Healthy
</p>
<div class="checkbox-option text-left">
<div class="inner"></div>
<input type="radio" name="MERGE3" value="Simply Healthy" />
</div>
</div>
<div class="col-sm-3">
<p class="mb16">
Paleo
</p>
<div class="checkbox-option text-left">
<div class="inner"></div>
<input type="radio" name="MERGE3" value="Paleo" />
</div>
</div>
<div class="col-sm-3">
<p class="mb16">
Vegetarian
</p>
<div class="checkbox-option text-left">
<div class="inner"></div>
<input type="radio" name="MERGE3" value="Vegetarian" />
</div>
</div>
<div class="col-sm-3">
<p class="mb16">
Gluten-Free
</p>
<div class="checkbox-option text-left">
<div class="inner"></div>
<input type="radio" name="MERGE3" value="Gluten-Free" />
</div>
</div>
<hr>
</div>
<div class="overflow-hidden">
<div class="col-sm-6 col-sm-offset-3">
<h6 class="uppercase">
2. How many people are you cooking for?
</h6>
<div class="select-option">
<i class="ti-angle-down"></i>
<select name="MERGE4">
<option selected value="Default">Select An Option</option>
<option value="google">1</option>
<option value="website">2</option>
<option value="friend">3</option>
<option value="friend">4</option>
<option value="friend">5</option>
<option value="other">6</option>
</select>
</div>
</div>
<hr>
</div>
<div class="overflow-hidden">
<h6 class="uppercase">
3. How long do you typically have to prepare meals?
</h6>
<div class="col-sm-3">
<p>
Less than 20 min. </p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE5" value="less than 20" />
</div>
</div>
<div class="col-sm-3">
<p>20 - 35 min.</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE5" value="20-35" />
</div>
</div>
<div class="col-sm-3">
<p>35 - 60 min.</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE5" value="35-60" />
</div>
</div>
<div class="col-sm-3">
<p>60+ min.</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE5" value="60+" />
</div>
</div>
<hr>
</div>
<div class="overflow-hidden">
<h6 class="uppercase">
3. How adventurous are you with cooking?
</h6>
<div class="col-sm-4">
<p>
I like simple food, thanks </p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE6" value="I like simple food, thanks" />
</div>
</div>
<div class="col-sm-4">
<p>I'll try it if it sounds good</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE6" value="I'll try it if it sounds good" />
</div>
</div>
<div class="col-sm-4">
<p>I'll try anything!</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE6" value="I'll try anything!" />
</div>
</div>
<hr>
</div>
<div class="overflow-hidden">
<h6 class="uppercase">
4. What ingredients would you like to avoid?
</h6>
<div class="col-sm-2">
<p>All Dairy</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="All Dairy" />
</div>
</div>
<div class="col-sm-2">
<p>Cheese</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Cheese" />
</div>
</div>
<div class="col-sm-2">
<p>Eggs</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Eggs" />
</div>
</div>
<div class="col-sm-2">
<p>Tree Nuts</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Tree Nuts" />
</div>
</div>
<div class="col-sm-2">
<p>Peanuts</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Peanuts" />
</div>
</div>
<div class="col-sm-2">
<p>Soy</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Soy" />
</div>
</div>
<div class="col-sm-2">
<p>Tofu</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Tofu" />
</div>
</div>
<div class="col-sm-2">
<p>Beef</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Beef" />
</div>
</div>
<div class="col-sm-2">
<p>Chicken</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Chicken" />
</div>
</div>
<div class="col-sm-2">
<p>Pork</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Pork" />
</div>
</div>
<div class="col-sm-2">
<p>Lamb</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Lamb" />
</div>
</div>
<div class="col-sm-2">
<p>Fish</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Fish" />
</div>
</div>
<div class="col-sm-2">
<p>Shellfish</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Shellfish" />
</div>
</div>
<div class="col-sm-2">
<p>Avocado</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Avocado" />
</div>
</div>
<div class="col-sm-2">
<p>Cilantro</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Cilantro" />
</div>
</div>
<div class="col-sm-2">
<p>Bell Pepper</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Bell Pepper" />
</div>
</div>
<div class="col-sm-2">
<p>Mushroom</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Mushroom" />
</div>
</div>
<div class="col-sm-2">
<p>Spicy Food</p>
<div class="radio-option">
<div class="inner"></div>
<input type="radio" name="MERGE7" value="Spicy Food" />
</div>
</div>
<div class="col-sm-8 col-sm-offset-2">
<div class="inner"></div>
<input type="text" name="MERGE8" class="col-md-12 " placeholder="Other (list separated by comma)" />
</div>
<hr>
</div>
<div class="overflow-hidden">
<h6 class="uppercase">
3. Your Account Details
</h6>
<input type="text" name="MERGE1" class="col-md-6 validate-required" placeholder="First Name*" />
<input type="text" name="MERGE2" class="col-md-6 validate-required" placeholder="Last Name*" />
<input type="text" name="MERGE0" class="col-md-12 validate-required validate-email" placeholder="Your Email Address*" />
<hr>
</div>
<div class="overflow-hidden">
<div class="col-sm-6 col-sm-offset-3">
<h6 class="uppercase">
4. Lastly, how did you hear of us?
</h6>
<div class="select-option">
<i class="ti-angle-down"></i>
<select name="MERGE9">
<option selected value="Default">Select An Option</option>
<option value="google">Google</option>
<option value="website">Facebook</option>
<option value="friend">Instagram</option>
<option value="friend">Friend Referral</option>
<option value="friend">Influencer Referral</option>
<option value="friend">Blog</option>
<option value="other">Other</option>
</select>
</div>
<input type="submit" class="button" name="submit" value="Subscribe to list">
<input type="hidden" name="ht" value="b750d7603dc70714c655f39211d647bec3bed54f:MTQ4MDQ4Nzc0OS44NTIx">
<input type="hidden" name="mc_signupsource" value="hosted">
</div>
</div>
</form>

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();

Categories