Can't store data using checkbox to database using codeigniter - arrays

I try to store some data using checkbox into my database, but it can't stored. Here is my code:
I try to store some data using checkbox into my database, but it can't stored. Here is my code:
I try to store some data using checkbox into my database, but it can't stored. Here is my code:
View:
<form method="post" action="<?php echo base_url().'igd/igd/input_airborne'?>">
<?php echo $this->session->flashdata('message_airborne');?>
<input type="text" class="form-control" name="KUNJUNGAN" value="<?php echo $igd->NOMOR ?>" readonly>
<input type="datetime-local" class="form-control" name="TANGGAL" value="<?php echo date("Y-m-d H:i:s") ?>">
<input type="text" class="form-control" name="OLEH" value="<?php echo $session_user->nip?>" readonly>
<input type="text" class="form-control" name="STATUS" value="1" readonly>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
TBC AKtif
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck2">
<label class="form-check-label" for="defaultCheck2">
Campak
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="DESKRIPSI" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
MDR TB
</label>
</div>
<button class="btn btn-sm btn-success mt-1 mb-1"> Masukkan</button>
</form>
Controller:
public function input_airborne(){
$DESKRIPSI = $this->input->post('DESKRIPSI');
$TANGGAL = $this->input->post('TANGGAL');
$OLEH = $this->input->post('OLEH');
$STATUS = $this->input->post('STATUS');
$KUNJUNGAN = $this->input->post('KUNJUNGAN');
$data = array(
'DESKRIPSI' => $DESKRIPSI,
'TANGGAL' => $TANGGAL,
'OLEH' => $OLEH,
'STATUS' => $STATUS,
'KUNJUNGAN' => $KUNJUNGAN
);
$this->M_Igd->input_airborne($data, 'igd_inim_airborne');
$this->session->set_flashdata('message_airborne','<div class="alert alert-success alert-dismissible mt-1 fade show" role="alert">
Airborne berhasil dimasukkan
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>');
redirect($_SERVER['HTTP_REFERER']);
}
the DESKRIPSI is field to storing my checkbox entry

it's been solved, i just change
$DESKRIPSI = $this->input->post('DESKRIPSI');
to
$DESKRIPSI = implode(', ', $_POST['DESKRIPSI']);
and don't forget to change name to
name="DESKRIPSI[]";
because data will be stored as array

You should specify:-
<input type="checkbox" name="Days[]" value="Daily">Daily<br>
Add [] to all names Days and work at php with this like as array.
After it, you can INSERT values at different columns at db, or use implode and save values into one column.
<html>
<body>
<form method="post" action="chk123.php">
Flights on: <br/>
<input type="checkbox" name="Days[]" value="Daily">Daily<br>
<input type="checkbox" name="Days[]" value="Sunday">Sunday<br>
<input type="checkbox" name="Days[]" value="Monday">Monday<br>
<input type="checkbox" name="Days[]" value="Tuesday">Tuesday <br>
<input type="checkbox" name="Days[]" value="Wednesday">Wednesday<br>
<input type="checkbox" name="Days[]" value="Thursday">Thursday <br>
<input type="checkbox" name="Days[]" value="Friday">Friday<br>
<input type="checkbox" name="Days[]" value="Saturday">Saturday <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
At PHP Server Side Script:-
$checkBox = implode(',', $_POST['Days']);

Related

AngularJs Form validation when select radio buttons

Hi i am learner in angularJS and in my form i have name and email fields and one radio group for gender selection and my requirement is when i select male then name field is required and if i select female then email field is required
I have tried below code but its not working can some one help me please
code:
<form class="form-horizontal alert alert-warning" name="empList" id="empForm" ng-submit="insertInfo(empInfo)">
<h3 class="text-center">Insert Employee Details Into Database</h3>
<div class="form-group">
<label for="Name">Employee Name:</label>
<input type="text" name="emp_name" class="form-control" placeholder="Enter Employee Name" ng-model="empInfo.name"
required="gender.value=='male'" />
</div>
<div class="form-group">
<p class="text-danger" ng-show="empList.emp_name.$invalid">Name field is Empty!</p>
</div>
<div class="form-group">
<label for="Email">Email Address:</label>
<input type="email" name="emp_email" class="form-control" placeholder="Enter Employee Email Address" ng-model="empInfo.email"
autofocus required="gender.value=='female'"/>
</div>
<div class="form-group">
<p class="text-danger" ng-show="empList.emp_email.$invalid>Invalid Email!</p>
</div>
<div class="form-group">
<label for="Gender">Gender:</label>
<label for="" class="radio-inline gender">
<input type="radio" name="emp_gender" value="male" ng-model="empInfo.gender" #gender="ng-model">Male
</label>
<label for="" class="radio-inline gender">
<input type="radio" name="emp_gender" value="female" ng-model="empInfo.gender" #gender="ng-model">Female
</label>
</div>
</form>
Maybe try with that validation:
HTML :
<form class="form-horizontal alert alert-warning" name="empList" id="empForm" ng-submit="insertInfo(empInfo)">
<h3 class="text-center">Insert Employee Details Into Database</h3>
<div class="form-group">
<label for="Name" ng-show="empInfo.gender != male_value">Employee Name is required</label>
<input type="text" name="emp_name" class="form-control" placeholder="Enter Employee Name" ng-model="empInfo.name"
required="gender.value=='male'" />
</div>
<div class="form-group">
<p class="text-danger" ng-show="empList.emp_name.$invalid">Name field is Empty!</p>
</div>
<div class="form-group">
<label for="Email" ng-show="empInfo.gender == male_value">Email Address is rquired</label>
<input type="email" name="emp_email" class="form-control" placeholder="Enter Employee Email Address" ng-model="empInfo.email"
required="gender.value=='female'"/>
</div>
<div class="form-group">
<p class="text-danger" ng-show="empList.emp_email.$invalid">Invalid Email!</p>
</div>
<div class="form-group">
<label for="Gender">Gender:</label>
<label for="" class="radio-inline gender">
<input type="radio" name="emp_gender" ng-value="male_value" ng-model="empInfo.gender">Male
</label>
<label for="" class="radio-inline gender">
<input type="radio" name="emp_gender" ng-value="female" ng-model="empInfo.gender" >Female
</label>
</div>
</form>
JS:
$scope.male_value = 'male';
plunker: http://plnkr.co/edit/Hi5t1gU5TIdNx670wHo1?p=preview

Custom Form Validation Not working in angularjs

I want to validate all the fields in this form by angular, but it is not working. I am new to angular and cant find what the problem is. None of the field in this form is being validated
<form class="form-horizontal" role="form" name="commentForm" ng-submit="submitComment()" novalidate>
<div class="form-group" ng-class="{'has-error': commentForm.name.$error.required && !commentForm.name.$pristine}">
<label for="name" class="col-xs-2">Your Name</label>
<div class="col-xs-10">
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Your Name" ng-model="dishComment.author">
<span class="help-block" ng-show="commentForm.name.$error.required && !commentForm.name.$pristine">Your Name is Required</span>
</div>
</div>
<div class="form-group">
<label for="rating" class="col-xs-2">Number of Stars</label>
<div class="col-xs-10">
<label class="radio-inline">
<input type="radio" name="rating" id="rating" value="1" ng-model="dishComment.rating"> 1
</label>
<label class="radio-inline">
<input type="radio" name="rating" id="rating" value="2" ng-model="dishComment.rating"> 2
</label>
<label class="radio-inline">
<input type="radio" name="rating" id="rating" value="3" ng-model="dishComment.rating"> 3
</label>
<label class="radio-inline">
<input type="radio" name="rating" id="rating" value="4" ng-model="dishComment.rating"> 4
</label>
<label class="radio-inline">
<input type="radio" name="rating" id="rating" value="5" ng-model="dishComment.rating"> 5
</label>
</div>
</div>
<div class="form-group" class="{'has-error': commentForm.comments.$error.required && !commentForm.comments.$pristine}">
<label for="comments" class="col-xs-2">Your comments</label>
<div class="col-xs-10">
<textarea class="form-control" id="comments" name="comments" rows="12" ng-model="dishComment.comment"></textarea>
<span class="help-block" ng-show="commentForm.comments.$error.required && !commentForm.comments.$pristine">Please Write a comment</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" ng-disabled="commentForm.$invalid">Submit Comment</button>
</div>
</div>
</form>
I think you only missed required in input element.
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Your Name" ng-model="dishComment.author" required>
I just added required for one input element and its working.
Please check jsfiddle
I am using input fields, something like below structure. as Nitish said, you must need to write required in input element.
AppForm is a form name.
<md-input-container flex="50" flex-gt-xs="33" md-is-error="AppForm.txtApplicationUrl.$invalid && (AppForm.$submitted || AppForm.txtApplicationUrl.$dirty)">
<label for="input_0">Your label</label>
<input type="text" ng-model="applicationDetails.Applicationurl" name="txtApplicationUrl" tabindex="0" id="txtApplicationUrl" aria-invalid="false" required><div class="md-errors-spacer"></div>
<div ng-messages="AppForm.txtApplicationUrl.$error" ng-if="AppForm.$submitted || AppForm.txtApplicationUrl.$touched">
<div ng-message="required">Custom Message</div>
</div>
</md-input-container>

Angular and not angular forms within the same page

I have two forms on a single page. One form I am adding/deleting which is working fine. Now in the second form (which I don't want to do anything through angular)
But I am not able to submit this(second form). Both the forms are inside my app. Anybody have any idea please share.
I can see when I refresh the page "ng-pristine ng-valid" classes are added in my second form.
This is my first form
<div class="address address-form" ng-hide="!isEdit">
<form class="edit-address-form" ng-submit="updateAddress(currentAddress.aid);">
<div class="form-group">
<label class="sr-only" for="first_name">First name </label>
<input type="text" class="form-control" id="first_name" value="testing" name="first_name" value="{{currentAddress.first_name}}" placeholder="First name" required ng-model="currentAddress.first_name">
</div>
<div class="form-group">
<label class="sr-only" for="last_name">Last name</label>
<input type="text" class="form-control" id="last_name" name="last_name" placeholder="Last name" ng-model="currentAddress.last_name" >
</div>
<div class="form-group">
<label class="sr-only" for="phone">Phone/mobile</label>
<input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" ng-model="currentAddress.phone">
</div>
<div class="form-group">
<label class="sr-only" for="street">Street address</label>
<input type="text" class="form-control" id="street" name="street" placeholder="Street address" ng-model="currentAddress.street">
</div>
<div class="form-group">
<label class="sr-only" for="city">City</label>
<input type="text" class="form-control" id="city" name="city" placeholder="City" ng-model="currentAddress.city" >
</div>
<div class="form-group">
<label class="sr-only" for="postal_code">Postal code</label>
<input type="text" class="form-control" id="postal_code" name="postal_code" placeholder="Postal code" ng-model="currentAddress.postal_code" >
</div>
<div class="form-group">
<label class="sr-only" for="country">Country</label>
<input type="text" class="form-control" id="country" name="country" placeholder="Country" autofocus ng-model="currentAddress.country">
</div>
<div class="form-group">
<div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
<div class="alert alert-success" role="alert" ng-show="successMsg">{{successMsg}}</div>
<button type="submit" class="btn btn-lg btn-primary btn-block" id="button-update-address" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Updating address...">Update address</button>
</div>
</form>
</div>
This one second form
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Payment Summary</h3>
</div>
<div class=" ">
<form id="confirm-order" name="confirm_order" method="POST" action="">
<div class="form-group">
<?php
if($con->returned_rows):
$row = $con->fetch_assoc();
?>
<table class="table">
<tr>
<td> Sub total </td>
<td><?php print $row['subtotal'] ;?><input type="hidden" name="subtotal" value="<?php print $row['subtotal'] ;?>"/></td>
</tr>
<tr>
<td>Total items </td>
<td><?php print $row['total_qty'] ;?></td>
</tr>
<tr>
<td>Shipping</td>
<td><?php //print $row['total_qty'] ;?></td>
</tr>
</table>
<?php endif; ?>
</div>
<div class="form-group">
<input type="submit" name="confirm" class="btn btn-lg btn-primary btn-block" value="Confirm order"/>
</div>
</form>
</div>
angular has directive named form, because of which it considers your form directive in angular-scope.
if you want this directive to be out of angular-scope, use ngNonBindable
<form ng-non-bindable>
.....
</form>

How to create an object from form data in Angular

I have a pretty complex object that I need to send from a form in Angular.
Basically the object looks like this:
vm.formData = {
active: 1,
parse_tree : {
exlude: [],
include: [],
tag: ''
},
tag: '',
term: ''
}
My problem is creating new objects inside the include or exclude arrays.
Not sure how to do that.
Basically if you type in a tag name inside the row with "With all of these" as the label, it needs to create a new object inside of the include array, and if you click the checkbox 'Exact match' next to the tag input, it needs to add exact : 1. If 'Exact match' is unchecked, then exact : 0.
parse_tree : {
exlude: [],
include: [
{
exact: 1,
term: "hello"
}
],
tag: ''
}
My form HTML:
<div class="row">
<div class="col-sm-2 advanced-label">Main Tag:</div>
<div class="col-sm-4">
<input ng-model="tc.formData.term"
id="new-main-tag"
type="text"
class="form-control"
placeholder="tag">
<input ng-model="tc.formData.parse_tree.include.obj.exact"
ng-true-value="1" ng-false-value="0"
for="new-main-tag"
type="checkbox">
<em>Exact match</em>
</div>
<div class="col-sm-4">
<select ng-model="tc.formData.tag"
class="form-control manage-source-input-tag">
<option value="companies">companies</option>
<option value="news" selected="">news</option>
<option value="people">people</option>
<option value="products">products</option>
</select>
</div>
<div class="col-sm-2">
<button ng-click="tc.showSimpleForm()"
class="btn btn-info btn-sm switch-btn">Switch to simple</button>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">
With all of these:
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll1"
id="with-all-1" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-1">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll2"
id="with-all-2" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-2">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll3"
id="with-all-3" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-3">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll4"
id="with-all-4" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-4">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll5"
id="with-all-5" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-5">
<em>Exact match</em>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">
With none of these:
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-1" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-1">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-2" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-2">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-3" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-3">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-4" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-4">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-5" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-5">
<em>Exact match</em>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">Tag Notes:</div>
<div class="col-md-5">
<textarea></textarea>
<input type="checkbox" aria-label="exact-match">
<em>Unsure</em>
</div>
<div class="col-md-5"></div>
</div>
<div class="row advanced-action-row">
<button class="btn btn-success btn-sm manage-term-add">Save</button>
</div>
For includes: (do same for excludes)
vm.formData = {
active: 1,
parse_tree : {
exlude: [],
include: [{}, {}, {}, {}, {}],
tag: ''
},
tag: '',
term: ''
}
Use ng-repeat:
<div class="col-sm-2" ng-repeat="smth in vm.formData.parse_tree.include">
<input ng-model="smth.term" type="text" class="form-control" placeholder="tag">
<input type="checkbox" ng-model="smth.exact">
<em>Exact match</em>
</div>
Now if u really need exact:1 and nothing otherwise, modify checkbox:
<input type="checkbox" ng-click="change(smth)">
In controller define change func:
if (smth.term) {
delete smth.term;
} else {
smth.term = 1;
}

Form Closing Tag Not Showing In Console

its very strange that i am closing the form input field tags but even though i didn’t find it in console.even my form value didn't getting posted.
here is my code
<form ng-submit="updatepersonel()" ng-repeat="update in userDetail">
<div class="form-group">
<input type="text" class="form-control full" ng-model="perupdate.firstname" ng-value="update.firstname" />
<label for="exampleInputPassword1">First Name</label>
<div class="form-group">
<label for="exampleInputPassword1">Last Name</label>
<input type="text" class="form-control" ng-model="perupdate.lastname" ng-value="update.lastname" />
</div>
<div class="form-group" />
<label for="exampleInputPassword1">Phone</label>
<input type="text" class="form-control full" ng-model="perupdate.firstname" ng-value="update.phone" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Location</label>
<input type="text" class="form-control full" ng-model="perupdate.location" ng-value="update.location" />
</div>
<button class="btn btn-success" type="submit">Update</button>
</form>
Edited::
<div class="form-group">
<form ng-submit="updatepersonel()" ng-repeat="update in userDetail">
<input type="text" class="form-control full" ng-model="perupdate.firstname" ng-value="update.firstname" />
<label for="exampleInputPassword1">First Name</label>
<div class="form-group">
<label for="exampleInputPassword1">Last Name</label>
<input type="text" class="form-control" ng-model="perupdate.lastname" ng-value="update.lastname" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Phone</label>
<input type="text" class="form-control full" ng-model="perupdate.firstname" ng-value="update.phone" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Location</label>
<input type="text" class="form-control full" ng-model="perupdate.location" ng-value="update.location" />
</div>
<button class="btn btn-success" type="submit">Update</button>
</form>
</div>
i have solved my issue.
what i was doing i was trying to get the data in ng-value.
But when i try to bind data in my ng-model i get the solution
js
$scope.perupdate= {
firstname: key.firstname,
lastname : key.lastname,
phone : key.phone,
location : key.location,
};
view
<input type="text" class="form-control full" ng-model="perupdate.firstname">

Resources