If I click on one check box another check box also checked.
addquiz.php
<?php
$unique_id = time().'_'.uniqid(true);
$userid = $this->session->userdata('cp_userid');
?>
<!-- DC QUIZZ -->
<form class="addquizform" id="quiz_form_<?php echo $unique_id;?>" data-form = "<?php echo $unique_id;?>" data-user = '<?php echo $userid ?>'>
<input type="hidden" name="sid" value="<?php echo $sectionId;?>">
<input type="hidden" name="cid" value="<?php echo $courseId;?>">
<div class="dc-quizz-info dc-course-item">
<div class="dc-content-title">
<h5 class="xsm black">Quiz : Title of quiz</h5>
<div class="course-region-tool">
<input type="button" value = "Save" class="mc-btn-3 btn-style-1 savequiz save" id="save_quiz_<?php echo $unique_id;?>">
</div>
</div>
<div class="quizz-body dc-item-body">
<div class="form-item form-checkbox checkbox-style">
<input type="checkbox" id="showanswer" value="1" name="showanswer">
<label for="showanswer">
<i class="icon-checkbox icon md-check-1"></i>
Show Answer
</label>
</div>
<div class="form-item form-checkbox checkbox-style">
<input type="checkbox" id="limittime">
<label for="limittime">
<i class="icon-checkbox icon md-check-1"></i>
Limit time
</label>
</div>
<div class="time">
<div class="form-item">
<input type="text" name="limittime">
<label for="">mins</label>
</div>
</div>
<div class="form-item">
<input type="text" placeholder="Quiz Title" class="fullwidth" name="quiztitle">
</div>
<div class="form-item">
<input type="text" placeholder="Short introduction" class="fullwidth" name="quizintro">
</div>
</div>
</div>
</form>
<!-- END / DC QUIZZ -->
when I go to add one more quiz it asks to check the check box, but when I clicked on check box above check box also checked. How to over come this problem.
Please Check The Name as well as id You Defined there is missing an id and name for checkbox
<div class="dc-quizz-info dc-course-item">
<div class="dc-content-title">
<h5 class="xsm black">Quiz : Title of quiz</h5>
<div class="course-region-tool">
<input type="button" value = "Save" class="mc-btn-3 btn-style-1 savequiz save" id="save_quiz_<?php echo $unique_id;?>">
</div>
</div>
<div class="quizz-body dc-item-body">
<div class="form-item form-checkbox checkbox-style">
<input type="checkbox" id="showanswer" value="1" name="showanswer">
<label for="showanswer">
<i class="icon-checkbox icon md-check-1"></i>
Show Answer
</label>
</div>
<div class="form-item form-checkbox checkbox-style">
<input type="checkbox" name="limitcheck" id="limitcheck">
</div>
<div class="time">
<label for="limittime">
<i class="icon-checkbox icon md-check-1"></i>
Limit time
</label>
<div class="form-item">
<input type="text" value="" id="limittime" name="limittime">
<label for="">mins</label>
</div>
</div>
<div class="form-item">
<input type="text" placeholder="Quiz Title" class="fullwidth" name="quiztitle">
</div>
<div class="form-item">
<input type="text" placeholder="Short introduction" class="fullwidth" name="quizintro">
</div>
</div>
</div>
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);
I have a form like below:
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].title" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].isbn" placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0].price" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
How to get value of this form in php $_Post because the name of fields are like <br/>name="book[0].title"**<br/>?
and there are many dynamic different name input fields.
If you can use for multiple books then use book[0].title like below,
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
If you want to use same form then change name of all textbox like,
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][isbn]." placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0][price]" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="submit" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
And get value of this form like echo $_POST['book'][0]['title'];
I hope this can help you.
You need to change name attribute,
<div class="col-xs-4">
<input type="text" class="form-control" name="book_title" placeholder="Title" />
</div>
book[0].title, this is not valid name.
You can now get something like this,
$_POST['book_title']
I'm using the HTML5 input date type. After posting, I see this input empty, and all the other inputs (HTML4 types) are OK.
What could be the reason?
This is my form:
<form action="/SGM/index.php?r=manager/addcoach_post" method="post">
<div class="registerFeildArea2">
<div class="registerTxtP2">Family name</div>
<div class="registerFeild">
<input name="lname" type="text" value="" size="" class="registerFeildValue" />
</div>
</div>
<div class="registerFeildArea">
<div class="registerTxtP2">First name</div>
<div class="registerFeild">
<input name="fname" type="text" value="" size="" class="registerFeildValue" />
</div>
</div>
<div class="registerFeildArea2">
<div class="registerTxtP2">Address</div>
<div class="registerFeild">
<input name="address" type="text" value="" size="" class="registerFeildValue" />
</div>
</div>
<div class="registerFeildArea">
<div class="registerTxtP2">City</div>
<div class="registerFeild">
<input name="city" type="text" value="" size="" class="registerFeildValue" />
</div>
</div>
<div class="registerFeildArea2">
<div class="registerTxtP2">Birthdate</div>
<div class="birthDayFeild">
<input name="bdate" id="meeting" type="date" value="2011-01-13"/>
</div>
</div>
<div class="AddBtn"><input name="Next" type="submit" value="הוסף" class="AddBtnValue" /></div>
</form>
And when I get to the actionAddcoach_post(), all the fields are OK except for the bdate.
What could be the reason?
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.