php not receives data from ajax FormData - php

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

Related

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'>

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>

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.

Two Forms In a HTML Document

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.

Categories