input type hidden using onclik - codeigniter

I have a problem when entering data into the database, where I want to enter the province_name attribute, but what is stored in the database is the id
my code
<div class="form-group col-md-4">
<label>Province Name</label>
<select name="province_order" id="provinsi" class="form-control select2" style="width: 100%;">
<option value="0">-PILIH-</option>
<?php foreach($data->result() as $row):?>
<option value="<?php echo $row->id_prov;?>"><?php echo $row->nama_provinsi;?></option>
<?php endforeach;?>
</select>
<input type="text" name="province_order">
</div>
function myFunction() {
var x = document.getElementById("provinsi").value;
document.getElementById("klik").innerHTML = x;
}
nama_provinsi not save in database, but id save.
how to save the province__name attribute

Try this:-
<div class="form-group col-md-4">
<label>Province Name</label>
<select name="province_order" id="provinsi" class="form-control select2" style="width: 100%;">
<option value="0">-PILIH-</option>
<?php foreach($data->result() as $row):?>
<option value="<?php echo $row->id_prov;?>" province="<?php echo $row->nama_provinsi;?>" ><?php echo $row->nama_provinsi;?></option>
<?php endforeach;?>
</select>
<input type="text" name="province_order">
</div>
function myFunction() {
var x = $("#provinsi").attr('province');
//document.getElementById("klik").innerHTML = x;
}

Related

How to show a new column after using select2 in laravel?

I have a form and using select2 for filter. I want to show new column by using this select2.
I don't know its possible or not but i want to do this . using jquery or something, can someone reference to me about this? its my form for my input
<form class="form-prevent-multiple-submits" data-toggle="validator" action="{{route('update_sarpras_aduan'),'test'}} " method="post">
#csrf
{{method_field('patch')}}
<div class="form-group">
<label class="control-label" for="title">Nama Unit:</label>
<input type="text" name="nama_unit" id="nama_unit" class="form-control" data-error="Please enter title." required disabled/>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Tanggal Aduan:</label>
<textarea name="created_at" class="form-control" id="tgl_aduan" data-error="Please enter description." readonly ></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Pengadu:</label>
<input type="text" name="nama_pengadu" class="form-control" id="nama_pengadu" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Isi Aduan </label>
<textarea name="aduan" id="aduan" class="form-control" rows="3" placeholder="Isi Aduan atau Keluhan ..." readonly ></textarea>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Teknisi:</label>
<input type="text" name="nama_teknisi" class="form-control" id="nama_teknisi" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
----------------here this select2---------------------------
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
--------------------------------------------------
<div class="form-group">
<label>Status Saat Ini (Jangan Lupa Diganti)</label>
<select name="status" id="status" class="form-control">
<option value="Tindakan Lanjutan">Tindakan Lanjutan</option>
<option value="Selesai">Selesai</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Tindakan Pelaksana </label>
<textarea name="tindakan" id="tindakan" class="form-control" rows="3" placeholder="Isi Tindakan Yang dilakukan" required ></textarea>
</div>
<div class="form-group">
<label>Kondisi Alat </label>
<select name="status_alat" id="status_alat" class="form-control">
<option value="Baik">Baik</option>
<option value="Rusak Ringan">Rusak Ringan</option>
<option value="Rusak Berat">Rusak Berat</option>
</select>
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="id" id="id" value="">
<input type="hidden" name="user_id" id="user_id" value="">
<input type="hidden" name="ipsrs_id" id="ipsrs_id" value="">
<input type="hidden" name="teknisi_id" id="teknisi_id" value="">
<input type="hidden" name="ended_at" id="ended_at" value="">
<div class="form-group">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" id="button" class="btn btn-success crud-submit-edit button-prevent-multiple-submits">
<i class="spinner fa fa-spinner fa-spin" ></i>
Submit</button>
</div>
</form>
after using this select2 , will showing a new form . can someone references to me about this ?
//select input
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true" onchange="Show()">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
//new form
<div id="divid" style="display:none">
<form method="" action="">
#csrf
</form
<div>
//javascript code
<script>
function Show()
{
var fieldValue = $('#alat_id').val();
if(fieldValue == "")
{
document.getElementById("divid").style.display = 'none';
}
else{
document.getElementById("divid").style.display = 'inline'
}
}
</script>

Laravel Error during update - Undefined variable: id

I am working on a project using Laravel-5.8
protected $table = 'ratings';
protected $fillable = [
'rating_type',
'rating_value',
'rating_description',
];
public function rules()
{
return [
'rating_type' => 'required|numeric|min:1|max:10|unique:appraisal_ratings,rating_type,company_id'.$this->id,
];
}
The rating has an id column, and that's the primary key. Why I checked it against company_id is that different companies can have the same rating type.
Controller
public function edit($id)
{
$rating = Rating::where('id', $id)->first();
return view('ratings.edit')
->with('rating', $rating)
->with('rating_types', $this->rating_types)
->with('rating_descriptions', $this->rating_descriptions)
->with('rating_values', $this->rating_values);
}
public function update(UpdateRatingRequest $request, $id)
{
$rating = Rating::find($id);
$rating->rating_type = $request->rating_type;
$rating->rating_value = $request->rating_value;
$rating->rating_description = $request->rating_description;
$rating->save();
Session::flash('success', 'Rating is updated successfully');
return redirect()->route('ratings.index');
}
edit.blade
<form action="{{route('ratings.update', ['id'=>$rating->id])}}" method="post" class="form-horizontal" enctype="multipart/form-data">
{{ csrf_field() }}
<input name="_method" type="hidden" value="PUT">
<div class="card-body">
<div class="form-body">
<div class="row">
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Rating:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Rating" tabindex="1" name="rating_type" style="width: 100%;">
<option value="">Select Rating</option>
#foreach($rating_types as $k => $rating_type)
<option value="{{$k}}" #if($rating->rating_type == $k) selected #endif>{{$rating_type}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Description:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Description" tabindex="1" name="rating_description" style="width: 100%;">
<option value="">Select Description</option>
#foreach($rating_descriptions as $k => $rating_description)
<option value="{{$k}}" #if($rating->rating_description == $k) selected #endif>{{$rating_description}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Rating Score:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Rating Score" tabindex="1" name="rating_value" style="width: 100%;">
<option value="">Select Rating Score</option>
#foreach($rating_values as $k => $rating_value)
<option value="{{$k}}" #if($rating->rating_value == $k) selected #endif>{{$rating_value}}</option>
#endforeach
</select>
</div>
</div>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">{{ trans('global.save') }}</button>
<button type="button" onclick="window.location.href='{{route('ratings.index')}}'" class="btn btn-default">Cancel</button>
</div>
</form>
When I clicked on the save button to update, I got this error:
rating_type already exists.
That error should not have occured since I am doing update.
How do I resolve it?
Thank you.
You are checking the unique on update wrong
Unique Rule Usage
unique:table,column,except,idColumn
* 3rd param is for value for column to except and 4th is for column to except
Fix
//App\Http\Requests\UpdateRatingRequest
'rating_type' => 'required|numeric|min:1|max:10|unique:table_name,rating_type,table_primary_key'.$this->id,

Populate Form Based on dropdown value in Codeigniter

I have about 30 different forms that will be displayed in a wizard, a form will be displayed based on the value from the dropdown selected, if all forms are created in a view file it doesn't seem effective, I try to save each form in the database and it will Called based on the dropdown value but not as expected, please help with this problem.
this is the code example that I saved into the database:
<label>Yang Bertandatangan Dibawah ini:</label>
<div class="form-group row">
<label class="col-form-label col-lg-2">Nama</label>
<div class="col-lg-10">
<select name="pemberi" class="form-control select-search" required data-fouc>
<option value="">--pilih--</option>
<?php
if(is_array($pegawai)){
foreach($pegawai as $row){
?>
<option value="<?php echo $row->nip;?>"><?php echo $row->nama;?></option>
<?php
}
}
?>
</select>
</div>
</div>
<label>MEMERINTAHKAN:</label>
<div class="form-group row">
<label class="col-form-label col-lg-2">Kepada:</label>
</div>
<div class="form-group row">
<label class="col-form-label col-lg-2">Nama:</label>
<div class="col-lg-10">
<select name="penerima" class="form-control select-search" required data-fouc>
<option value="">--pilih--</option>
<?php
if(is_array($pegawai)){
foreach($pegawai as $row){
?>
<option value="<?=$row->nip;?>"><?=$row->nama;?></option>
<?php
}
}
?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-lg-2">Jabatan:</label>
<div class="col-lg-10">
<select name="jabatan_penerima" class="form-control select-search" required data-fouc>
<option value="">--pilih--</option>
<?php
if(is_array($pembuat)){
foreach($pembuat as $row){
?>
<option value="<?=$row->id;?>"><?=$row->nama_jabatan;?></option>
<?php
}
}
?>
</select>
</div>
</div>
<label>Untuk:</label>
<div class="row">
<div class="col-md-9">
<div class="form-group">
<textarea rows="10" cols="4" class="form-control" placeholder="Isi Perintah" name="isisurat" id="isisurat" required></textarea>
</div>
</div>
</div>
The code runs well if it is directly written in source code, but different if called from the database
as expected if I write the code in page directly:
If I save the code in database and call based on value of dropdown,it will show error:
Why don't you use normal load views based on a condition like in your index you would do this:
VIEW ONE
VIEW TWO
// and so on ...
Then in your controller:
public function your_method($your_view)
{
$data['view'] = $this->load->view($your_view, null, TRUE);
// Setting third param as true will return the view as a string
$this->load->view('main_view', $data);
}
Now in your main view you have a variable called view of your requested view just echo it in your main content area.

I'm facing the issue mentioned below while displaying the price list for the domains suggested

While getting tld's and domain name from enom api I'm getting error as "Unsupported Operand" for particular tld's like "co.in","in.net". Suggest me a solution to solve this.
Find below my controller code
public function domaincheck(Request $request)
{
$sld = $request['sld'];
$tld = $request['tld'];
$response = file_get_contents('https://reseller.enom.com/interface.asp?command=check&sld='. $sld .'&tld='. $tld .'&uid=decksys&pw=resellpw&responsetype=xml');
$data = simplexml_load_string($response);
$configdata = json_encode($data);
$final_data = json_decode($configdata,true);// Use true to get data in array rather than object
// dd($final_data);
}
The blade code is given below:
<div class="form-group">
<div class=" col-lg-2"></div>
<div class="col-lg-8">
<div class="input-group m-b">
<span class="input-group-addon" style="padding-left:10px; background-color: #999;" class='unclickable'>www</span>
<input type="text" name="sld" class="form-control" required>
<span class="input-group-addon">
<select class="form-control" name="tld" style="width: 100px;">
<option value="com">com</option>
<option value="in">in</option>
<option value="info">info</option>
<option value="org">org</option>
<option value="co.in">co.in</option>
<option value="in.net">in.net</option>
<option value="net">net</option>
<option value="biz">biz</option>
</select>
</span>
<span class="input-group-addon">
<button type="submit" class="btn btn-sm btn-success" >Submit</button>
</span>
My route is given below:
Route::get('/registerdomain','EnomController#domaincheck');

country drop down not being populate with data codeigniter

country drop down not being populate with data codeigniter, can any body help me out, i want list of country on view so that i could select country. when i add select code in view for drop down it hides the list and save button.
my model
public function get_Country() {
$this->db->select('code, name')->from("country");
$query = $this->db->get();
return $query->result_array();
}
my controller
public function get_Country() {
$ctry = $this->job_post_model->get_Country();
// debug($ctry);
}
my view code
<div class="row">
<div class="span8">
<div class="about-heading">
<div class="head-menu"> </div>
</div>
<div class="about-section">
<div class="about-content rigs-content">
<form name="jobpost" action=" <?php echo base_url('employer/job_post/post_job'); ?>" method="post">
<h2>Your Job Detail :</h2>
<div class="invest-form">
<ul>
<li class="pull-right">
<label>Job Category:</label>
<input type="text" name="jobcat" value="" placeholder="Enter Job Category*" />
</li>
<li class="pull-right">
<label>Job Title:</label>
<input type="text" name="jobtitle" value="" placeholder="Enter Job Title*" />
</li>
<li>
<label>Job Type:</label>
<input type="text" name="jobtype" value="" placeholder="Enter Job Type*" />
</li>
<li class="pull-right">
<label>Preffered Age:</label>
<input type="text" name="age" value="" placeholder="Enter Job Title*" />
</li>
<li>
<label>Preffered Gender:</label>
<input type="text" name="gender" value="" placeholder="Enter Job Type*" />
</li>
<li>
<label>Job Description:</label>
<input type="text" name="desc" value="" placeholder="Enter Job Type*" />
</li>
<li class="pull-right">
<label>Location:</label>
<input type="text" name="location" value="" placeholder="Enter the Country*" />
</li>
<li>
<label>Post Code:</label>
<input type="text" id="post" rel="popover" data-trigger="hover" name="postcode" placeholder="Enter the City*" />
</li>
<li class="pull-right">
<label>Salary:</label>
<input type="text" id="salaries" name="salary" placeholder="Enter the Salary*" />
</li>
<li>
<li>
<label>Qualification:</label>
<input type="text" id="qualification" rel="popover" data-trigger="hover" name="qualification" placeholder="Enter Benifits*" />
</li>
<li class="pull-right">
<label>Category:</label>
<input type="text" id="category" class="span12" required name="category" placeholder="Enter Job Tags" />
</li>
<label>Benifits:</label>
<input type="text" id="benefits" rel="popover" data-trigger="hover" name="benefits" placeholder="Enter Benifits*" />
</li>
<li class="pull-right">
<label>Job Tags:</label>
<input type="text" id="jobtags" class="span12" required name="jobtag" placeholder="Enter Job Tags" />
</li>
<li class="pull-right">
<label>Career Level:</label>
<input type="text" id="career" class="span12" required name="career" placeholder="Enter Job Tags" />
</li>
<li>
<label>Country:</label>
<?php $countries = get_Country(); ?>
<select name="country">
<option>Select your country*</option>
<?php foreach ($countries as $country) { ?>
<option value="<?php echo $country->name ?>" </option>
<?php }
?>
</select>
</li>
<li class="pull-right">
<table id="question">
<th>Add Killer Questions</th>
<tr>
<td><input type="text" id="questions" name="question[]"/></td>
</tr>
</table>
<td><input type="button" id="btnAdd" class="button-add" onClick="insertTextBox()" value="Add More"></input></td>
</li>
<br>
<input type="submit" value="Save As Draft" class="button-next" />
</div>
</form>
<div class="wid-social">
</div>
</div>
</div>
</div>
<script>
var index = 1;
function insertTextBox(){
var text = document.getElementById("question");
var row=text.insertRow(text.rows.length);
var cell1=row.insertCell(0);
var t1=document.createElement("input");
t1.id = "question"+index;
t1.name = "question[]";
cell1.appendChild(t1);
var cell2=row.insertCell(1);
index++;
}
</script>
In model:
Repalce
return $query->result_array();
With
return $query->result();
In View :
Repalce
<?php $countries = get_Country(); ?>
<select name="country">
<option>Select your country*</option>
<?php foreach ($countries as $country) { ?>
<option value="<?php echo $country->name ?>" </option>
<?php }
?>
</select>
With
<?php $countries = get_Country(); ?>
<?php echo form_dropdown('country',$countries, 0,'required'); ?>
In Codeigniter Use Codeigniter From Dropdown
Your model is correct, but you do need to decide if you are going to access the data as an array or an object. That will dictate how you access your data in the View.
$query->result_array() returns an array
$query->result() returns an object
In your controller you need to use your model.
// Load your model into your controller
$this->load->model('your_model');
// use your_model method to set $data['countries']
$data['countries'] = $this->your_model->get_Country();
// You will access $countries in your view by passing it to your view
$this->load->view('your_view'), $data);
In your view, if you choose $query->result() in your model :
<select name="country">
<option>Select your country*</option>
<?php foreach ($countries as $country): ?>
<option value="<?php echo $country->name ?>"><?php echo $country->name ?></option>
<?php endforeach; ?>
</select>
Your controller didn't return anything, so need to modify controller as below.
controller :
public function get_Country() {
return $ctry = $this->job_post_model->get_Country();
}
and also your VIEW returning result as an array, you need to use $country['name'] in the place of $country->name.
VIEW:
<?php $countries = get_Country(); ?>
<select name="country">
<option>Select your country*</option>
<?php foreach ($countries as $country) { ?>
<option value="<?php echo $country['code'] ?>"><?php echo $country['name'] ?></option>
<?php }
?>
</select>

Resources