checkbox doesnt have a value php - php

I'm trying to turn a input into a checkbox on my form. When checked I want the value to be 1 and unchecked to be zero. I tried a few things but on submit the value doesnt get added into the db.
HTML-1:
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" for="input-active"><?php echo $entry_active; ?></label>
<div class="input-active required">
<input type="checkbox" name="active" value="0" placeholder="<?php echo $text_active; ?>" id="input-active" class="form-control" />
</div>
<?php if (isset($error_date_starting)) { ?>
<label class="text-danger"><?php echo $error_code; ?></label>
<?php } ?>
</div>ut type="checkbox" name="active" value="0" placeholder="<?php echo $text_active; ?>" id="input-active" class="form-control" />
</div>
<?php if (isset($error_date_starting)) { ?>
<label class="text-danger"><?php echo $error_code; ?></label>
<?php } ?>
</div>
HTML-2:
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" for="input-active"><?php echo $entry_active; ?></label>
<div class="input-active required">
<input type="hidden" name='active' value='0' placeholder="<?php echo $text_active; ?>" id="input-active" class="form-control" />
<input type="checkbox" name='active' value='1' placeholder="<?php echo $text_active; ?>" id="input-active" class="form-control" />
</div>
<?php if (isset($error_date_starting)) { ?>
<label class="text-danger"><?php echo $error_code; ?></label>
<?php } ?>
</div>
I tried a few Javascripts solutions but none worked:
<script type="text/javascript">
$('#input-active').on('change', function(){
this.value = this.checked ? 1 : 0;
// alert(this.value);
}).change();
</script>
UPDATE!!
Still not working I've changed code following suggestions still not doing what I'd like.
New HTML:
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" for="input-active"><?php echo $entry_active; ?></label>
<div class="input-active required">
<input type="checkbox" name='active' value='0' placeholder="<?php echo $text_active; ?>" id="input-active" class="form-control" />
</div>
<?php if (isset($error_date_starting)) { ?>
<label class="text-danger"><?php echo $error_code; ?></label>
<?php } ?>
</div>
New JS:
<script type="text/javascript">
$("#input-active").change(function() {
if(this.checked) {
$("#input-active").val('1');
} else {
$("#input-active").val('0');
}
});
</script>

To catch the toggled event on input type please use the following function
$("#input-active").change(function() {
if($(this).is(':checked')) {
console.log('checked')
$(this).val(1);
} else {
console.log('un checked')
$(this).val(0);
}
console.log($(this).val())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" for="input-active">In active</label>
<div class="input-active required">
<input type="checkbox" name='active' value='0' placeholder="Active" id="input-active" class="form-control" />
</div>
</div>

Related

Codeigniter, registration autofill form field

i am creating a registration page and I want to autofill the the value of certain input field whenever i choose a specific department like .when i choose the department A . it will autofill who is the supervisor on that department on my registration .how do i do it ?
this is my html view code
<?php if (validation_errors()) { ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-alert" aria-hidden="true"></span><strong> Error!</strong><p><?= validation_errors(); } ?></p></center>
</div>
<?php if (isset($error)){ ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><strong> Error! </strong><?= $error ?> </center>
</div>
<?php } ?>
<div class="container-fluid">
<center> <h2>Register</h2></center>
<hr class="colorgraph">
<form class="form-horizontal" action="<?= base_url().'login/registeruser' ?>" method="post">
<div class="form-group">
<label for="username" class="col-sm-2 control-label "><?php if(form_error('username')){ echo '<p style="color:#a94442"> * Username </p>';} else { echo 'Username'; } ?></label>
<div class="col-sm-6">
<input type="text" class="form-control <?php if (form_error('username')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="username" name="username" placeholder="Username" value="<?php echo set_value('username'); ?>">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label "><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Password </p>';} else { echo 'Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="password" name="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="confpassword" class="col-sm-2 control-label"><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Confirm Password </p>';} else { echo 'Confirm Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="confpassword" name="confpassword" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label "><?php if(form_error('email')){
echo '<p style="color:#a94442"> * Email </p>';} else { echo 'Email'; } ?></label>
<div class="col-sm-6">
<input type="email" class="form-control <?php if (form_error('email')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="email" name="email" placeholder="Email"
value="<?php echo set_value('email'); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label"><?php if(form_error('fname')||form_error('mname')||form_error('lname')){ echo '<p style="color:#a94442"> * Full Name </p>';} else { echo 'Full Name'; } ?></label>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('fname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="fname" name="fname" placeholder="First Name" value="<?php echo set_value('fname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" value ="sa" class="form-control <?php if (form_error('mname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="mname" name="mname" placeholder="Middle Name" value="<?php echo set_value('mname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('lname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="lname" name="lname" placeholder="Last Name" value="<?php echo set_value('lname'); ?>">
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Gender</label>
<label class="radio-inline col-sm-1 control-label">
<input type="radio" name="gender" id="gender" value="M" selected="selected"> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="F"> Female
</label>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Department</label>
<select name="Department">
<option value="stem">STEM</option>
<option value="gas">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>
<div class="form-group">
<div class="col-sm-4 control-label">
<h3><strong>
Captcha
<?=$image; ?></strong></h3>
<input type="text" id="captcha" name="captcha" height="50px" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> Back</button>
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</body>
i want to specifically use php code .how do i do it ? thanks
You can use jquery ajax functionality for the same.

how to print array values in different textbox

I have these values inside a table
and I want them to print in each of the textboxes like
Can anyone help me with that?
This is my code so far
PHP
<?php
$spnsrArr = $conn->query("SELECT bap_sponsors.* FROM bap_sponsors WHERE bap_id='$bapID'");
$row = mysqli_fetch_array($spnsrArr);
$spnsrName = $row['sponsors_name'];
$spnsrAge = $row['sponsors_age'];
$spnsrReligion = $row['sponsors_religion'];
$spnsrPlace = $row['sponsors_residence'];
?>
HTML
<label>SPONSOR #1</label>
<div class="form-group">
<div class="col-md-6">
<h5>Name:</h5>
<input type="text" name="$spnsName[]" class="form-control" value="<?php echo $spnsrName; ?>" disabled="" />
</div>
<div class="col-md-2">
<h5>Age:</h5>
<input type="number" name="age[]" class="form-control" value="<?php echo $spnsrAge; ?>" disabled="" />
</div>
<div class="col-md-4">
<h5>Religion:</h5>
<input type="text" name="spnsrreligion[]" class="form-control" value="<?php echo $spnsrReligion; ?>" disabled="" />
</div>
<div class="col-md-12">
<h5>Residence:</h5>
<input type="text" name="spnsrresidence[]" class="form-control" value="<?php echo $spnsrPlace; ?>" disabled="" /><br>
<hr>
</div>
</div>
Your query
$spnsrArr = $conn->query("SELECT bap_sponsors.* FROM bap_sponsors WHERE bap_id='$bapID'");
returns several rows. But
$row = mysqli_fetch_array($spnsrArr);
fetches only one.
You should iterate over results, calling mysqli_fetch_array several times. This is usually done with while:
$i = 0;
while ($row = mysqli_fetch_array($spnsrArr)) {
$spnsrName = $row['sponsors_name'];
$spnsrAge = $row['sponsors_age'];
$spnsrReligion = $row['sponsors_religion'];
$spnsrPlace = $row['sponsors_residence'];
$i++;
?>
<label>SPONSOR #<?php echo $i;?></label>
<div class="form-group">
<div class="col-md-6">
<h5>Name:</h5>
<input type="text" name="spnsName[]" class="form-control" value="<?php echo $spnsrName; ?>" disabled="" />
</div>
<div class="col-md-2">
<h5>Age:</h5>
<input type="number" name="age[]" class="form-control" value="<?php echo $spnsrAge; ?>" disabled="" />
</div>
<div class="col-md-4">
<h5>Religion:</h5>
<input type="text" name="spnsrreligion[]" class="form-control" value="<?php echo $spnsrReligion; ?>" disabled="" />
</div>
<div class="col-md-12">
<h5>Residence:</h5>
<input type="text" name="spnsrresidence[]" class="form-control" value="<?php echo $spnsrPlace; ?>" disabled="" /><br>
<hr>
</div>
</div>
<?php
}
Also note I removed $ in name="$spnsName[]".

update checkboxes using ajax php mysqli

this is my modal
<div class="modal fade bs-example-modal-lg" id="exampleModal<?php echo $row['t_id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel<?php echo $row['t_id'] ?>">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Termin Ansicht <font color="red">ID</font>: <b><?php echo $row['t_id'] ?></b> <font color="red">Call Agent</font>: <b><?php echo $row['username'] ?></b> <font color="red">Call Datum</font>: <b><?php echo date("d.m.y" , strtotime($row['datum'])) ?></b></h4>
</div>
<div class="modal-body">
<form>
<div class="row">
<div class="col-sm-3">
<input type="text" id="username" value="<?php echo $row['username']; ?>" class="form-control">
</div>
<div class="col-sm-3">
<input type="text" id="t_id" value="<?php echo $row['t_id']; ?>" class="form-control">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-1 control-label">Anrede</label>
<div class="col-sm-2">
<input type="text" id="anrede<?php echo $row['t_id']; ?>" value="<?php echo $row['anrede']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Vorname</label>
<div class="col-sm-3">
<input type="text" id="vorname<?php echo $row['t_id']; ?>" value="<?php echo $row['vorname']; ?>" class="form-control" onselectstart="return false" onpaste="return false;" onCopy="return false" onCut="return false" onDrag="return false" onDrop="return false">
</div>
<label class="col-sm-1 control-label">Nachname</label>
<div class="col-sm-3">
<input type="text" id="nachname<?php echo $row['t_id']; ?>" value="<?php echo $row['nachname']; ?>" class="form-control" onselectstart="return false" onpaste="return false;" onCopy="return false" onCut="return false" onDrag="return false" onDrop="return false">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-1 control-label">Strasse</label>
<div class="col-sm-3">
<input type="text" id="strasse<?php echo $row['t_id']; ?>" value="<?php echo $row['strasse']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">PLZ</label>
<div class="col-sm-3">
<input type="text" id="plz<?php echo $row['t_id']; ?>" value="<?php echo $row['plz']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Ort</label>
<div class="col-sm-2">
<input type="text" id="ort<?php echo $row['t_id']; ?>" value="<?php echo $row['ort']; ?>" class="form-control">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-1 control-label">Krankenkasse</label>
<div class="col-sm-3">
<input type="text" id="krankenkasse<?php echo $row['t_id']; ?>" value="<?php echo $row['krankenkasse']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Seit</label>
<div class="col-sm-3">
<input type="text" id="seit<?php echo $row['t_id']; ?>" value="<?php echo $row['seit']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Personen</label>
<div class="col-sm-1">
<input type="text" id="personen<?php echo $row['t_id']; ?>" value="<?php echo $row['personen']; ?>" class="form-control">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-1 control-label">Telefon</label>
<div class="col-sm-2">
<input type="text" id="telefon<?php echo $row['t_id']; ?>" value="<?php echo $row['telefon']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Termin</label>
<div class="col-sm-2">
<input type="date" id="termin<?php echo $row['t_id']; ?>" value="<?php echo $row['termin']; ?>" class="form-control">
</div>
<label class="col-sm-1 control-label">Uhrzeit</label>
<div class="col-sm-2">
<input type="text" id="time<?php echo $row['t_id']; ?>" value="<?php echo date("H:i", strtotime($row['time'])) ?>" class="form-control">
</div>
<div class="col-sm-2">
<select class="form-control" id="vermittler<?php echo $row['t_id']; ?>" value='<?php echo $row['vermittler'];?>'>
<option ><?php echo $row['vermittler'];?></option>
<?php
$result1 = ("SELECT * FROM users where type='berater'") or mysql_error();
$ilaz=mysql_query($result1);
while($rowa = mysql_fetch_array($ilaz)){
?>
<option id="berater" value = "<?php echo $rowa['username']; ?>" >
<?php echo $rowa['username']; ?>
</option>
<?php
}
?>
</select>
</div>
</div>
<br>
<div class="row">
<label for="ccomment" class="control-label col-lg-2">Bemerkung</label>
<div class="col-lg-4">
<textarea class="form-control " id="coment<?php echo $row['t_id']; ?>" required><?php echo $row['coment']; ?></textarea>
</div>
<label for="ccomment" class="control-label col-lg-1">Feedback</label>
<div class="col-lg-4">
<textarea class="form-control " id="feedback<?php echo $row['t_id']; ?>" ></textarea>
</div>
</div>
<br>
<div class="row">
<?php
$bfeedback = ("select id, user, feedback_b, datum from b_feedback where id='". (int)$_GET['t_id']."' order by datum desc" ) or mysql_error();
$bresult = mysql_query($bfeedback);
if($bfeedback === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($beraterfeedback = mysql_fetch_array($bresult)){
?>
<label for="b_feedback" class="control-label col-lg-2"><?php #echo $beraterfeedback['user'] ?><?php #echo $beraterfeedback['datum'] ?></label>
<td><font color="red"><?php echo $beraterfeedback['user'] ?></font></td>
<td><?php echo $beraterfeedback['datum'] ?></td>
<td><?php echo $beraterfeedback['feedback_b'] ?></td><br> <hr>
<?php
}
?>
</div>
<br>
<div class="row">
<div class="col-sm-20">
<?php
$iAstatus = explode(",",$row['Astatus']);
foreach($arrAstatus as $aAstatus)
{
if(in_array($aAstatus,$iAstatus))
echo "<label class='col-sm-1 control-label'><input type='checkbox' class='s' value='".$aAstatus."' checked> .$aAstatus. </label>";
else
echo "<label class='col-sm-1 control-label'><input type='checkbox' class='s' value='".$aAstatus."'> .$aAstatus.</label>" ;
}
?>
</div>
<div class="col-sm-1">
<input type="text" id="positiv<?php echo $row['t_id']; ?>" value="<?php echo $row['abschluss']; ?>" class="form-control">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-5 control-label"><p style="color:red"><font size="2">Personen Angaben (Namen, Geburtsdatum)?</font></p></label>
<div class="col-sm-5">
<textarea class="form-control " id="personen_angaben<?php echo $row['t_id']; ?>" ><?php echo $row['personen_angaben']; ?></textarea>
</div>
</div>
<br>
<div class="row">
<label class="col-sm-5 control-label"><p style="color:red"><font size="2">Sind Sie (bzw. jemand in Ihrem Haushalt) momentan in ärztliche Behandlung/Therapie(Physio) oder steht Ihnen eine Behandlung bevor?</font></p></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="fr_1<?php echo $row['t_id']; ?>" value="<?php echo $row['fr_1']; ?>" >
</div>
</div>
<br>
<div class="row">
<label class="col-sm-5 control-label"><p style="color:red"><font size="2">Zusatzfrage wenn JA- Dies könnte Auswirkungen auf Ihren Wechsel haben. Deshalb, welcher Art ist denn diese Behandlung?</font></p></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="fr_2<?php echo $row['t_id']; ?>" value="<?php echo $row['fr_2']; ?>">
</div>
</div>
<br>
<div class="row">
<label class="col-sm-5 control-label"><p style="color:red"><font size="2">Nehmen Sie (bzw. jemand in Ihrem Haushalt) regelmässig Medikamente?</font></p></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="z_fr_2<?php echo $row['t_id']; ?>" value="<?php echo $row['z_fr_2']; ?>">
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2"><p style="color:red">Zusatzfrage wenn JA- Was sind das für Medikamente oder für was müssen Sie diese nehmen?</p></font></label>
<div class="col-sm-5">
<input class="form-control" id="fr_3<?php echo $row['t_id']; ?>" value="<?php echo $row['fr_3']; ?>" >
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2"><p style="color:red">Hatten Sie (bzw. jemand an Ihrem Haushalt) in den letzten 10 Jahren eine Operation oder steht eine bevor?</p></font></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="z_fr_3<?php echo $row['t_id']; ?>" value="<?php echo $row['z_fr_3']; ?>">
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2"><p style="color:red">Was für eine Operation wann /ist das?</p></font></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="fr_4<?php echo $row['t_id']; ?>" value="<?php echo $row['fr_4']; ?>" >
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2"><p style="color:red">Wenn die Operation in der Vergangenheit war: beziehen Sie nun eine IV-Rente oder ist dies folgenlos geheilt?</p></font></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="z_fr_4<?php echo $row['t_id']; ?>" value="<?php echo $row['z_fr_4']; ?>" >
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2"><p style="color:red">Falls 1 Person krank ist - Können Sie sich vorstellen, einen Teil Ihrer Familie zu versichern?</p></font></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="fr_5<?php echo $row['t_id']; ?>" value="<?php echo $row['fr_5']; ?>" >
</div>
</div>
<div class="row">
<label class="col-sm-5 control-label"><font size="2">Status</font></label>
<div class="col-sm-5">
<input class="form-control" type="text" id="fr_6<?php echo $row['t_id']; ?>" value="<?php echo $row['status']; ?>">
</div>
</div>
<div class="row">
<label class="col-sm-4 control-label"> </label>
<div class="col-sm-3">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" onclick="updatedata('<?php echo $row['t_id'] ?>')" data-dismiss="modal" class="btn btn-primary">Update</button>
</div>
</div>
and this jquery ajax
function updatedata(str){
var t_id = str;
var anrede = $('#anrede'+str).val();
var vorname = $('#vorname'+str).val();
var nachname = $('#nachname'+str).val();
var strasse = $('#strasse'+str).val();
var plz = $('#plz'+str).val();
var ort = $('#ort'+str).val();
var krankenkasse = $('#krankenkasse'+str).val();
var seit = $('#seit'+str).val();
var personen = $('#personen'+str).val();
var telefon = $('#telefon'+str).val();
var termin = $('#termin'+str).val();
var time = $('#time'+str).val();
var vermittler = $('#vermittler'+str).val();
var coment = $('#coment'+str).val();
var feedback = $('#feedback'+str).val();
var s = new Array();
$("input:checked").each(function() {
s.push($(this).val());
});
var positiv = $('#positiv'+str).val();
var personen_angaben = $('#personen_angaben'+str).val();
var fr_1 = $('#fr_1'+str).val();
var fr_2 = $('#fr_2'+str).val();
var z_fr_2 = $('#z_fr_2'+str).val();
var fr_3 = $('#fr_3'+str).val();
var z_fr_3 = $('#z_fr_3'+str).val();
var fr_4 = $('#fr_4'+str).val();
var z_fr_4 = $('#z_fr_4'+str).val();
var fr_5 = $('#fr_5'+str).val();
var fr_6 = $('#fr_6'+str).val();
var datas="anrede="+anrede+"&vorname="+vorname+"&nachname="+nachname+"&strasse="+strasse+"&plz="+plz+"&ort="+ort+"&krankenkasse="+krankenkasse+"&seit="+seit+"&personen="+personen+"&telefon="+telefon+"&termin="+termin+"&time="+time+"&vermittler="+vermittler+"&coment="+coment+"&feedback="+feedback+"&s[]="+s+"&positiv="+positiv+"&personen_angaben="+personen_angaben+"&fr_1="+fr_1+"&fr_2="+fr_2+"&z_fr_2="+z_fr_2+"&fr_3="+fr_3+"&z_fr_3="+z_fr_3+"&fr_4="+fr_4+"&z_fr_4="+z_fr_4+"&fr_5="+fr_5+"&fr_6="+fr_6;
alert(datas);
$.ajax({
type: "POST",
url: "updatedata.php?t_id="+t_id,
data: datas,
cache: false
}).done(function( data ) {
$('#info').html(data);
viewdata();
});
}
and this the php array
$arrAstatus = array("Wollte k T","Kunde Ni err.","St .Gef","N.Zuhaus","Offen","Negativ","MJV","Behan.","Abgesagt","Positiv");
Now when i submit the form it update all unchecked checkboxes.
how can i do that it update only checked checkboxes and after refresh to show me it checked
Problems:
you are creating your checkbox Ids as an array syntax s[]. I believe you are confusing it with the name attribute. Change this: id='s[]' to this: name='s[]'
<font> is no longer supported. Also, the opening and closing tags of that element is not correct.
where is your ajax? where's your form? where's your submit button? Without this info, you leave us to assume this is a form, and that your jquery function gets triggered when the form is submitted. If thats the case, then you need your actionattribute with the URL that AJAX will use to send the request.
Summary:
Please be more descriptive, show your HTML, your PHP, jQuery properly so that we can best help you. In order to solve your problem you need to send an AJAX request. Find out how to do that, implement that in your code, and then we can continue from there.
It seems you need help urgently with this. The main problem I see is that you are missing the name attribute in your form elements. You need to use name attributes so that when you gather the data in jQuery you can use the .serialize() function. I will sort of redo your code in a way that I think you have it working. I will delete all that bootstrap stuff and the non-related code so that you can see what I am doing:
I am assuming your data is coming from your database. I will use an array called $data to mimic that result set:
//your database data
$data = array(
array(
"t_id" => 1,
"username" => "john",
"Astatus" => "Wollte k T,Kunde Ni err.,N.Zuhaus"
)
);
//your comparison data
$arrAstatus = array("Wollte k T", "Kunde Ni err.", "St .Gef", "N.Zuhaus", "Offen", "Negativ", "MJV", "Behan.", "Abgesagt", "Positiv");
Next, I assume you iterate through each result as $row and create your forms. I removed your classes/ids because we do not need them for this purpose. Instead, I placed the needed name attributes in your inputs:
<?php foreach ($data as $row) { ?>
<form>
<input type="text" name="username" value="<?php echo $row['username']; ?>" class="form-control">
<input type="text" name="t_id" value="<?php echo $row['t_id']; ?>" class="form-control">
<?php
$iAstatus = explode(",", $row['Astatus']);
foreach ($arrAstatus as $aAstatus) {
if (in_array($aAstatus, $iAstatus))
echo "<label><input type='checkbox' name='s[]' value='$aAstatus' checked>$aAstatus</label><br>";
else
echo "<label><input type='checkbox' name='s[]' value='$aAstatus'>$aAstatus</label><br>";
}
?>
<input type="submit">
</form>
<?php } ?>
Lastly, your jQuery should be triggered when the form is submitted using the .submit() function. Once submitted, use .serialize() to obtain all inputs with the name attributes and send it through AJAX:
$('form').submit(function () {
var datas = $(this).serialize();
$.ajax({
type: "POST",
url: "submit.php",
data: datas,
cache: false
}).done(function (data) {
console.log(data);
});
return false;
});
Hope this helps.

How to add radio button and Test schedule with date and time?

I had created the form with some details but I added the radio button and it is not working for getting the values to print on my mail and I have tried to add the date and time using dropdown list but it is not working fine.
the radio buttons should be required.It has to show as in below image as alert for radio button and Test schedule but it is not getting as in the image
Please any one help me.It is very important for me.
My form
<form action="http://www.labwise.in/devel/zensearch/order" id="bookingtest" method="post">
<div class="fieldset">
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="testname" class="required"><em>*</em><?php echo $this->__('Test Name') ?> </label>
<div class="input-box">
<input type="text" id="testname" name="testname" value="<?php echo $_GET['name']?>" class="input-text required-entry" title="<?php echo $this->__('Test Name') ?>" />
</div>
</div>
<div class="field">
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?> </label>
<div class="input-box">
<input type="text" id="city" name="city" value="<?php echo $_GET['city']?>" class="input-text required-entry" title="<?php echo $this->__('City') ?>" />
</div>
</div>
</li>
<li>
<label for="location" class="required"><em>*</em><?php echo $this->__('Location') ?> </label>
<div class="input-box">
<input type="text" id="location" name="location" value="<?php echo $_GET['location']?>" class="input-text required-entry" title="<?php echo $this->__('Location') ?>" />
</div>
</li>
<li class="fields">
<div class="field">
<label for="cname" class="required"><em>*</em><?php echo $this->__('Name') ?> </label>
<div class="input-box">
<input type="text" id="cname" name="cname" value="" class="input-text required-entry" title="<?php echo $this->__('Name') ?>" />
</div>
</div>
<div class="field">
<label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="email" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</div>
</div>
</li>
<li>
<label for="mobile" class="required"><em>*</em><?php echo $this->__('Mobile Number') ?> </label>
<div class="input-box">
<input type="text" id="mobile" name="mobile" value="" class="input-text required-entry validate-mobileno" title="<?php echo $this->__('Mobile Number') ?>" />
</div>
</li>
<li>
<label class="required"><em>*</em><?php echo $this->__('Sample Collection') ?> </label></li>
<li>
<div class="radio_button">
<input type="radio" name="radio" class="input-text required-entry validate-select" value="I will visit Lab"> I will visit Lab
</div>
<div>
<input type="radio" name="radio" class="input-text required-entry validate-select" value="Visit me at home/office +Rs50.00" > Visit me at home/office +Rs50.00
</div>
</li>
<li>
<label for="requiredby" class="required"><em>*</em><?php echo $this->__('Test Schedule') ?> </label>
<div class="input-box">
<input type="text" id="requiredby" name="requiredby" value="" class="input-text required-entry" title="<?php echo $this->__('Test Schedule') ?>" style="width: 150px;" />
<img style="" title="Select Date" id="date_select_trig" alt="" src="<?php echo $this->getSkinUrl("images/calendar.gif");?> "/>
<select name="date_time" id="date_time" class="input-text required-entry validate-select" style="width: 50px;" />
<option value=""><?php echo $this->__('--')?></option>
<option value="1"><?php echo $this->__('1')?></option>
<option value="2"><?php echo $this->__('2')?></option>
<option value="3"><?php echo $this->__('3')?></option>
<option value="4"><?php echo $this->__('4')?></option>
<option value="5"><?php echo $this->__('5')?></option>
<option value="6"><?php echo $this->__('6')?></option>
<option value="7"><?php echo $this->__('7')?></option>
<option value="8"><?php echo $this->__('8')?></option>
<option value="9"><?php echo $this->__('9')?></option>
<option value="10"><?php echo $this->__('10')?></option>
<option value="11"><?php echo $this->__('11')?></option>
<option value="12"><?php echo $this->__('12')?></option>
</select>
<b>:</b>
</div>
</li>
</ul>
</div>
<div class="button">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<button id= "submit" type="submit" class="button" title="<?php echo $this->__('Book Test') ?>" name="send" id="send2"><span><span><?php echo $this->__('Book Test') ?></span></span></button>
</div>
</form>
<script src="<?php echo Mage::getBaseUrl('js')."calendar/calendar.js" ?>" type="text/javascript"></script>
<script src="<?php echo Mage::getBaseUrl('js')."calendar/calendar-setup.js" ?>" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo Mage::getBaseUrl('js') ?>calendar/calendar-win2k-1.css" />
<?php echo $this->getLayout()->createBlock('core/html_calendar')->setTemplate('page/js/calendar.phtml')->toHtml();?>
<script type="text/javascript">
if(Validation) {
Validation.addAllThese([
['validate-mobileno','Enter correct mobile number (Eg:9986858483)',
function(v){
//var timePat ="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";
var timePat ="^{0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";
// var matchArray = v.match(timePat);
if(v.length > 0){
if(v.length !=10){
return false;
}else if(v[0]!=9 && v[0]!=8 && v[0]!=7){
return false;
}
return true;
}else {
return false;
}
}
]])
};
var dataForm = new VarienForm('bookingtest', true);
</script>
<script type="text/javascript">
// <![CDATA[
Calendar.setup({
inputField : 'testschedule',
ifFormat : '%d-%b-%Y',
showsTime: false,
button : 'date_select_trig',
singleClick : true,
});
// ]]>
</script>
This is one way of getting rid of that deep level of nesting.
var visit = document.getElementById('visit-required');
var form = document.forms.bookingtest;
form.addEventListener('submit', function(e){
if(!form.lab.checked && form.office.checked){
e.preventDefault();
visit.style.display = 'block';
}
});
.marked-required{
color: #FF0000;
}
.message-required{
display: none;
color: #FF0000;
}
#options{
border: 2px solid #FF0000;
}
#datetime > input{
display: inline-block;
vertical-align: top;
}
Place this php in the file you want to post to.
/* example.php */
<?php
print_r($_POST);
?>
<form action="example.php" id="bookingtest" method="post">
<strong>Sample collection <span class='marked-required'>*</span></strong>
<div id='options'>
<input type='radio' name='visit' id='lab'/>I will visit Lab<br/>
<input type='radio' name='visit' id='office'/>Visit me at home/office + Rs50.00
</div>
<small class='message-required' id='visit-required'>Please select one of the option.</small>
<br/>
<strong>Test schedule<span class='marked-required'>*</span></strong>
<div id='datetime'>
<input type='text' />
<select>
<option>From</option>
</select>
<select>
<option>To</option>
</select>
<select>
<option>AM</option>
<option>PM</option>
</select>
<small class='message-required'>This is a required option</small>
</div>
<input type='submit' id='submit' value='Submit'/>
</form>

How to stop form submission after validation has suceeded

I was wondering if there was a way I could stop the form from being submitted normally after Jquery validation has actually succeeded.
I would like some other function to take care of submitting the form. I'd like the form to be validated but not submitted. Hope anyone can help
I'm using the VarienForm validation class.
here'a an example below:
var newform = new VarienForm('newform', true);
Thanks in advance.
here's my form:
<form id="newform" >
<div class="fieldset">
<h2 class="legend">User Details</h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="firstname" class="required"><em>*</em>First Name</label>
<div class="input-box">
<input name="firstname" id="firstname" title="First Name of Staff" value="<?php if (isset($user->firstname)){ echo $user->firstname; } ?>" class="input-text required-entry" type="text" tabindex="1"/>
</div>
</div>
<div class="field">
<label for="lastname" class="required"><em>*</em>Last Name</label>
<div class="input-box">
<input name="lastname" id="lastname" title="Last Name of Staff" value="<?php if (isset($user->lastname)){ echo $user->lastname; } ?>" class="input-text required-entry" type="text" tabindex="2"/>
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="othername" class="required"><em>*</em>Other Name (s)</label>
<div class="input-box">
<input name="othername" id="othernames" title="Other Name(s)" value="<?php if (isset($user->othername)){ echo $user->othername; } ?>" class="input-text" type="text" tabindex="3"/>
</div>
</div>
<div class="field">
<label for="phone" class="required"><em>*</em>Phone Number</label>
<div class="input-box">
<input name="phone" id="phone" title="Phone Number" value="<?php if (isset($user->phone)){ echo $user->phone; } ?>" class="input-text validate-number" type="text" tabindex="4"/>
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="username" class="required"><em>*</em>User Name</label>
<div class="input-box">
<input name="username" id="username" title="User Name" value="<?php if (isset($user->username)){ echo $user->username; } ?>" class="input-text required-entry" type="text" tabindex="5" />
</div>
</div>
<div class="field">
<label for="email" class="required"><em>*</em>Email</label>
<div class="input-box">
<input name="email" id="email" title="User Email" value="<?php if (isset($user->email)){ echo $user->email; } ?>" class="input-text validate-email" type="text" tabindex="6" />
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="password" class="required"><em>*</em> Password</label>
<div class="input-box">
<input name="password" id="password" title="Password" value="<?php // if (isset($user->password2)){ echo $user->password2d; } ?>" class="input-text validate-password required-entry" type="password" tabindex="7"/>
</div>
</div>
<div class="field">
<label for="password2" class="required"><em>*</em>Confirm Password</label>
<div class="input-box">
<input name="password2" id="password" title="Confirm Password" value="<?php // if (isset($user->password2)){ echo $user->password2; } ?>" class="input-text validate-password required-entry validate-cpassword" type="password" tabindex="8"/>
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="Role" class="required"><em>*</em>Role</label>
<div class="input-box">
<?php $roles = Role::find_all(); if ($roles){ ?>
<select name="role" id="role" class="required-entry" tabindex="9" value="">
<option value="" selected="selected">SELECT ROLE</option>
<?php foreach ($roles as $role) : ?>
<option value="<?php echo $role->id; ?>"><?php echo $role->name ?></option>
<?php Endforeach; ?>
</select>
<?php } else { echo "No Roles Found! Add Role"; } ?>
</div>
</div>
<div class="field">
<label for="Status" class="required"><em>*</em>Status</label>
<div class="input-box">
<select name="status" id="status" class="required-entry" tabindex="10" value="">
<option value="1" selected="selected">Active</option>
<option value="0">Inactive</option>
</select>
</div>
</div>
</li>
</ul>
<div class="buttons-set">
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
<input type="submit" name="submit" value="SAVE" class="buttons-set" />
</div>
</div>
</form>
Since you tagged jQuery, I'm going to give you a jquery solution:
$("#newform").submit(function() {
return false;
});
Similarly, you can use this variation (actually this is the right way to do it)
$(document).ready(function() {
// I'm not familiar with VarienForm
// but the statement below runs once all DOM elements
// become available.
var newform = new VarienForm('newform', true);
// The block of code below only runs after you click
// the submit button in your form with id="newForm"
$("#newform").submit(function(e) {
// you can put a condition here, for example:
// if your form validation is correct return true;
// otherwise run e.preventDefault()
e.preventDefault();
});
});
You need to return false in your "onSubmit" method.
More details are explained in this similar post: How to prevent buttons from submitting forms
You can give the form an onsubmit="function" and in the function do an return false, before you return the false run another function.
First take a look at code i wrote below :
var x=true;
$('#newform').submit(function(e){
if(x) e.preventDefault();
myfun($(this));
});
function myfun(p) {
//lots of work...(simulating with timeout it could be anything ie. 2*2*2...)
setTimeout(function(){
x=false;
p.submit();
},1000);
}
Link to demo: >>> http://jsfiddle.net/techsin/QwWfb/
Main idea stop execution the time you want it to stop...but when ready to submit after doing whatever, let the stopping function know that it's not needed anymore. So when you call submit it actually goes through.
Control x to control submitting.

Categories