When I press on submit button on form in CodeIgniter,
if I am at XController/loadX
and my action is YController/loadY,
the URL becomes like Xcontroller/loadX/Ycontriller/loadY,
and I want it to be just YController/loadY.
<form name="SpecAccept"method="post"action="SpecialistController/loadDoctor">
<div class="form-group col-sm-12" id="myDiv" align="right">
<span><label>الولاية</label></span>
<select style="font-size:12px" class="form-control" id="state_name" onchange="change(this)">
<option>--- اختر الولاية ---</option>
<?php
foreach($states as $Object){
echo '<option value="'.$Object->StateID.'">'.$Object->StateName.'</option>';
}
?>
</select>
</div>
<div class="form-group col-sm-6" id="myDiv" align="right">
<span><label>المهنة</label></span>
<select style="font-size:12px" class="form-control" id="career_name" >
<option>--- اختر المهنة ---</option>
<?php
foreach($careers as $Object){
echo '<option value="'.$Object->CareerID.'">'.$Object->CareerName.'</option>';
}
?>
</select>
</div>
<div class="form-group col-sm-6" id="myDiv" align="right">
<span><label>المستشفى</label></span>
<select style="font-size:12px" class="form-control" id="hospitals" name="Hospitals" >
<option value="0" isSelected>اختر الولاية اولاً</option>
</select>
</div>
<div class="form-group col-sm-12">
<button type="sumbit">عرض</button>
</div>
</form>
what is the problem and how to fix it?
try to use javascript
<button type="button" onclick="Function_name();" >عرض</button>
then in a javascript you can do that
<script>
function Function_name(){
alert ('I AM HERE');
document.SpecAccept.submit();
}
</script>
that alert is to see if the button works and enter in the function.
if that not work try to change the type of form like this
<?php
$attributes = array(
'id' => 'SpecAccept',
'name' => 'SpecAccept',
'autocomplete' => 'off',
'enctype' => 'multipart/form-data',
);
echo form_open_multipart('SpecialistController/loadDoctor'); // this is the open <form>
?>
then for closed it replaces </form> tag for
<?php echo form_close();?>
First, you need to define base URL in config.php file like this
$config['base_url'] = 'http://localhost/projectfoldername/';
Now in form action URL
<form name="SpecAccept"method="post"action="<?php echo base_url('SpecialistController/loadDoctor'); ?> ">
Related
I am fetching data from DB Table in form. I want to automatically select the mobile number of the same customer whose name I select from the list but I am unable to do that because I've to select the mobile number manually. How can I link both enteries?
<form>
<div class="form-group">
<label for="customer">Customer Name</label>
<select class="form-control" name="customer">
<option value="">Choose Customer</option>
<?php foreach ($customers as $key => $customer): ?>
<option value="{{$customer->id}}">{{$customer->name}} </option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="id">Customer's Mobile</label>
<?php foreach ($customers as $key => $customer): ?>
<input type="number" class="form-control" name="customer_mobile" value="{{$customer->mobile}}">
<?php endforeach; ?>
</div>
</form>
Well, a simple jQuery snippet can get done this. You may improve this as you wish.
<form>
<div class="form-group">
<label for="customer">Customer Name</label>
<select class="form-control" name="customer" id="customer">
<option value="">Choose Customer</option>
<?php foreach ($customers as $key => $customer): ?>
<option data-mobile-number="{{$customer->mobile}}" value="{{$customer->id}}">{{$customer->name}} </option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="id">Customer's Mobile</label>
<input type="number" class="form-control" name="customer_mobile" value="" id="mobile_number">
</div>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#customer").on('change', function(){
$("#mobile_number").val($(this).find("option:selected").data('mobileNumber'));
});
});
</script>
Working JSFiddle demo : https://jsfiddle.net/83oaqfzd/2/
Note : I assume you have included the jQuery lib in your project.
I have been tying to make JQuery repeater plugin works fetching data from database. I already have this working inserting the data into the database but I have not look retrieving the inserted data to edit it.
This is the code I have in php and html.
<div id="repeater">
<div class="repeater-heading" align="left">
<a role="button" class="btn btn-info repeater-add-btn" ><span class="glyphicon glyphicon-plus"> </span>Add Transactional Impact</a>
</div>
<div class="clearfix"></div>
<br>
<div class="items" data-group="impacts">
<div class="item-content">
<div class="form-group">
<?php
$query_raw_num = "SELECT * FROM revenue_impact_number WHERE revenue_impact_id='".$id."' ";
$results = $mysqli->query($query_raw_num);
while($impacts = $results->fetch_assoc()){
?>
<div class="row" data-repeater-item>
<div class="col-md-2">
<label>Region:</label>
<select data-skip-name="true" data-name="region_id[]" id="region_id" class="form-control">
<option value="">-- Select --</option>
<?php
$query_raw = "SELECT regions_id, regions_name FROM regions ";
$result = $mysqli->query($query_raw);
while($row = $result->fetch_assoc()){
?>
<option value="<?php echo $row['regions_id']; ?>" <?php echo ($row['regions_id']==$impacts['region_id'] ? 'selected' : ''); ?> ><?php echo $row['regions_name']; ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-2">
<label>Product:</label>
<select data-skip-name="true" data-name="product_id[]" id="product_id" class="form-control">
<option value="">-- Select --</option>
<?php
$query_raw_products = "SELECT product_id, product_name FROM products ";
$result_products = $mysqli->query($query_raw_products);
while($products = $result_products->fetch_assoc()){
?>
<option value="<?php echo $products['product_id']; ?>" <?php echo ($products['product_id']==$impacts['product_id'] ? 'selected' : ''); ?> ><?php echo $products['product_name']; ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-2">
<label>Impact:</label>
<input type="text" data-skip-name="true" data-name="impact_number[]" id="impact" value="<?php echo $impacts['impact_number'];?>" class="form-control" style="width:200px;"/>
</div>
<div class="col-md-2">
<label>Expected:</label>
<input type="text" data-skip-name="true" data-name="expected[]" id="expected" value="<?php echo $impacts['expected'];?>" class="form-control" style="width:200px;"/>
</div>
<div class="col-md-2" style="margin-top:24px;" align="center">
<a id="remove-btn" role="button" onclick="$(this).parents('.item-content').remove()" class="btn btn-danger" ><span class="glyphicon glyphicon-trash"> </span>Remove</a>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</di>
This is the script function I am using.
$(function(){
$('#repeater').createRepeater();
});
When the page load for the first time everything is displayed successfully. See below image
The issue I am having is that when I try to add new group of fields it is displaying the whole group again and when I click on remove button it is removing the whole data group as well. See below image.
While retrieving the existing data while edit there is an issue in repeater code. Comment below lines from "repeater.js" files
/*
if (key == 0) {
items.remove();
addItem(newItem, key);
}
*/
I'm new in CodeIgniter and still junior in programming, so don't be angry at me.
PS: don't be angry for my English too. ;)
I am creating small CMS for one project. Inside that project its few select tags, first ones have just a few values but the next ones, have many values, which depends to the one of the values, from select tag that i mention before.
Its everything ok with my database tables dependencies, etc. but I dont know how to make dependencies to show up in select tags. I tried to make it with Ajax, but I am still not make it, and I read that I can make it with codeIgniter libraries, is it true? Can any body can help me?
This is my view file:
<?php echo validation_errors('<p class="alert alert-dismissable alert-danger">'); ?>
<form method="post" action="<?php echo base_url(); ?>admin/engines/add">
<div class="row">
<div class="col-lg-6">
<h1>Engine Type</h1>
</div>
<div class="col-lg-6">
<div class="btn-group pull-right">
<input type="submit" name="submit" class="btn btn-success" value="Save">
Close
</div>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i>Dashboard</li>
<li><i class="fa fa-pencil"></i>Variklio Tipai</li>
<li class="active"><i class="fa fa-plus-square-o"></i>Pridėti Variklio tipą</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h2>Engine type One</h2>
<div class="form-group">
<label>Engine Name</label>
<input class="form-control" type="text" name="engine" value="<?php echo set_value('engine'); ?>" placeholder="Engine Type" >
</div>
<div class="form-group">
<label>Category</label>
<select name="brand" class="form-control">
<option value="category">Choose category</option>
<?php foreach($categories as $category) : ?>
<option value="<?php echo $category->id; ?>"><?php echo $category->category_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- END Category-->
<!-- *** Brand *** -->
<div class="form-group">
<label>Brand</label>
<select name="brand" class="form-control">
<option value="">Choose Brand</option>
<?php foreach ($brands as $brand) : ?>
<option value="<?php echo $brand->id; ?>"><?php echo $brand->v_brand_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- **** END Brand ***-->
<!-- *** Model *** -->
<div class="form-group">
<label>Model</label>
<select name="model" class="form-control">
<option value="">Choose model</option>
<?php foreach ($models as $model) : ?>
<option value="<?php echo $model->id; ?>"><?php echo $model->v_model_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- **** END MODEL ***-->
</div>
</div>
</div>
</form>
for example this is my view
<select name='list1' id='list1'>
<option value='1'>id 1</option>
<option value='2'>id 2</option>
<option value='3'>id 3</option>
<option value='4'>id 4</option>
<option value='5'>id 5</option>
</select>
this is 2nd dropdown list
<select name='list2' id='list2'>
</select>
now jquery code is
$("#list1").on("change",function(){
var value = $(this).val();
$.ajax({
url : "example.com/welcome/get_data",
type: "post",
data: {"value":value},
success : function(data){
$("#list2").html(data);
},
});
});
now my controller function is
public function get_data()
{
$value = $this->input->post("value");
$data = $this->mymodal->get_data($value);
$option ="";
foreach($data as $d)
{
$option .= "<option value='".$d->id."' >".$d->name."</option>";
}
echo $option;
}
my model function is
public function get_data($value)
{
$this->db->where("id",$value);
return $this->db->get("table_name")->result();
}
I have html select2,it can selected multiple option:
<div class="form-group">
<label class="col-sm-1 control-label no-padding-right" for="form-field-recipient">Recipient:</label>
<div class="col-sm-6 col-xs-12">
<span class="input-icon block col-xs-12 no-padding">
<select name="for" id="for" class="for" multiple="multiple" placeholder="For" style="width: 92%">
<?php
foreach($this->forList as $dataFor){
?>
<option value="<?php echo $dataFor['ohp_id'];?>"><?php echo $dataFor['title'];?> Of <?php echo $dataFor['name'];?></option>
<?php } ?>
<?php
foreach($this->group as $group){
?>
<option value="<?php echo $group['object_group_id'];?>"><?php echo $group['object_group_name'];?></option>
<?php } ?>
</select>
<i class="ace-icon fa fa-user col-xs-0"></i>
</span>
</div>
</div>
$(document).ready(function() {
$(".refnd").select2({placeholder: "Reference ND"});
$(".for").select2({placeholder: "For"});
And this jquery:
But in PHP,it just show 1 option selected. How To fix it?
Change the dropdown name as an array:
<select name="for" id="for" class="for" multiple="multiple" placeholder="For" style="width: 92%">
<select name="for[]" id="for" class="for" multiple="multiple" placeholder="For" style="width: 92%">
JS:
var selectedOpt = $('#for').val(); // it will return an array of selected options
// Now use the selectedOpt array in your ajax call
In the following code the Reset functionality is not working with this dropdown means onclick of Reset button textbox value get reset but the dropdown select is not reset to default value "select addvertize".
<form enctype="multipart/form-data" class="contact-form" name="deleteadvertize" id="deleteadvertize" action="" method="post">
<div class="row form-group">
<div class="col-xs-12">
<label>Select Advertize</label>
<div class="selector">
<?php
include 'config.php' ;
$result = mysql_query("select * from advertise");
echo '<select id="advt_id" name="advt_id" class="full-width selector">';
echo " <option value=''>Select One Advertize</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['advt_id'] ."'>" . $row['advt_title'] ."</option>";
}
echo "</select>"; ?>
</div>
</div>
</div>
<div align="center">
<button type="submit" class="btn-large">Submit</button>
<button type="reset" class="btn-large">Reset</button>
</div>
<form>
<div class="row form-group">
<div class="col-xs-12">
<label>Select Advertize</label>
<div class="selector">
<select id="advt_id" name="advt_id" class="full-width selector">
<option value=''>Select One Advertize</option>
<option value='1'>Select One </option>
</select>
</div>
</div>
</div>
<div align="center">
<button type="submit" class="btn-large">Submit</button>
<button type="reset" class="btn-large">Reset</button>
</div>
</form>
you need to you wrap your html in form tag
<form></form>
if still not work use jquery for this
$('select[name=advt_id] option').removeAttr('selected');
Reset works when you have <form></form> tag. Please check you have form tag or not ? if not the add.