intigrate wysiwyg with codeigniter - codeigniter

I'm using codeigniter and trying to pass content to the database using the WYSIWYG editor.
I installed the WYSIWYG into my VIEW like the below code.
<div class="blank">
<div class="blank-page">
<!------------- syam bek-------------->
<?php if(!empty($error)): ?>
<div class="alert alert-warning">
<strong>Warning!</strong> <?php echo $error; ?>
</div>
<?php endif;?>
<?php if(!empty($products)):?>
<?php $ver=array('id'=>'try','name'=>'try','class'=>'form-horizontal'); ?>
<?php echo form_open_multipart(base_url().'editproduct/edit',$ver);?>
<label>المنتج
<br>
<select class="selectpicker" data-show-subtext="true" data-live-search="true" name="select_product" onchange="[document.try.action='editproduct/show',document.try.submit()]">
<?php
if (count($products)>1) {
echo '<option selected></option>';
foreach ($products as $p):
echo "<option value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
elseif(count($products)==1){
foreach ($products as $p):
echo "<option selected value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
?>
</select>
<?php if(count($products)==1){
$name=$p->p_name;
$details=$p->details;
$price=$p->p_price;
}else{
$name="";
$details="";
$price="";
}
?>
</label>
</br>
<label>اسم المنتج
<input type="text" name="name" value="<?php echo $name;?>" class="form-control"/>
</label>
<br>
<label>تفاصيل للمنتج
<input type="text" name="details" value="<?php echo $details;?>" class="form-control" />
</label>
<br>
<label>سعر المنتج
<input type="text" name="price" value="<?php echo $price;?>" class="form-control" />
</label>
<br>
<br>
<br>
<div class="container">
<div class="hero-unit">
<div id="alerts"></div>
<div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="icon-font"></i><b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</div>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="icon-text-height"></i> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>
<li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>
<li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
</ul>
</div>
<div class="btn-group">
<a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
<a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
<a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="icon-strikethrough"></i></a>
<a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
<a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
<a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>
<a class="btn" data-edit="indent" title="Indent (Tab)"><i class="icon-indent-right"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>
<a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>
<a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>
<a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>
</div>
<div class="btn-group">
<a class="btn" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="icon-picture"></i></a>
<input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
</div>
<div class="btn-group">
<a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="icon-undo"></i></a>
<a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="icon-repeat"></i></a>
</div>
<input type="text" data-edit="inserttext" id="voiceBtn" x-webkit-speech="">
</div>
<div id="editor">
</div>
</div>
</div>
<button class="btn btn-warning" name="cancel" >الغاء</button>
<button type="submit" name="save" class="btn btn-primary">حفظ</button>
<button type="submit" name="del" class="btn btn-danger">حذف المنتج</button>
<?php echo form_close();?>
<?php else :?>
<?php echo "لايوجد منتجات ليتم التعديل عليها";?>
<?php endif;?>
</div>
</div>
check i trace the inspector from the broswer i found insertion happens in the <div id="editor">HERE</div>
i don't know to pass the DIV contents to the database, especially the DIV element not identified by name like other elements.
Thanks

You can use javascript and ajax to submit your form, this is rough outline of jquery solution
// listen for submit event on your form
$( "#try" ).submit(function( event ) {
event.preventDefault();
let content = $('#editor').val(); // get the value from the editor
let details = $("input[name='details']").val() // get the value of input with the name of 'details'
... // do the same for all other inputs
// validate inputs if desired
if(content == '') {
// for example do something if content is empty
return;
}
// collect all input data into one object
var data = {
content: content,
details: details,
...
}
// send ajax request to the server
$.ajax({
url : 'urlToYourBackendEndpoint',
type : 'POST',
data : data,
success : function(response) {
// check the response and redirect or show notice after submit here
},
error : function(request,error)
{
alert("Request: "+JSON.stringify(request));
}
});
});

Related

how to get the selected drop down value after update or refresh the page

how to get the selected drop down value after update or refresh the page,if i update the selected drop down value after refresh the page the drop down value will be updated previous one
<div class="panel panel-default">
<div class="panel-heading row">
<div class="col-md-4 col-sm-4 col-xs-4">State</div>
<div class="col-md-4 col-sm-4 col-xs-4 ellipsis" id="cstate"><?php
if (isset($s_state)) {
echo $s_state;
}
?>
</div>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse6">
<div class="profile-edit col-sm-4 col-xs-4 col-md-4 aj-textsix">
<?php if (empty($s_state[0]) || empty($s_state)): ?>
Add
<?php else: ?>
<i class="fa fa-pencil"></i> Edit
<?php endif; ?>
</div>
</a>
</div>
<div id="collapse6" class="panel-collapse collapse">
<div class="panel-body">
<div class="row">
<div class="col-md-7 col-lg-offset-2 text-center">
<label class="col-md-4">State</label>
<div class="col-md-8">
<select id="state" name="state" value="<?= (isset($s_state)) ? $s_state : null; ?>">
<option value="data1" selected="selected">Data 1</option>
<option value="data2">Data 2</option>
</select>
<input type="hidden" name="save_state" id="save_state" value="<?= (empty($s_state[0]) || empty($s_state)) ? 'Save' : 'Update'; ?>">
<?php if (empty($s_state[0]) || empty($s_state)): ?>
<button type="submit" class="btn btn-success aj-text-btnsix" data-target="#collapse6" data-toggle="collapse">Save</button>
<?php else: ?>
<button type="submit" class="btn btn-success aj-text-btnsix" data-target="#collapse6" data-toggle="collapse">Update</button>
<?php endif; ?>
<button type="button" data-target="#collapse6" data-toggle="collapse" class="btn btn-warning cancel-name">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
how to get the selected drop down value after update or refresh the page,if i update the selected drop down value after refresh the page the drop down value will be updated previous one
$(".aj-textsix").html(result.replace_textsix);
$(".aj-text-btnsix").html(result.btn_textsix);
$("#save_state").val(result.save_state);
$('#cstate').text($("#state").val());

want to pass the post value in to controller

Here am having the code like this
<div class="form-group">
<label class="col-lg-3 control-label">Start Date</label>
<div class="col-lg-5">
<div class="input-group">
<input type="text" required name="attendance_date" id="attendance_date" class="form-control datepicker" value="<?php echo date('Y-m-d');?>" data-date-format="<?= config_item('date_picker_format'); ?>" required>
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
<a data-toggle="modal" data-target="#myModal" type="button" name="update" href="<?php echo base_url();?>admin/attendance_confirmation/reject1/<?php echo $this->input->post('attendance_date');?>" id="update1" value="Reject" class="btn btn-danger ml" ><i class="fa fa-times"></i> <?= lang('reject') ?></a>
and my controller looks like this
public function reject1($date)
{
$data['date']=$date;
var_dump($data['date']);
$data['modal_subview'] = $this->load->view('admin/engineer_attendance_confirmation/attendance_confirmation_modal',$data,FALSE);
$this->load->view('admin/_layout_modal', $data);
}
but the value in the attendance_date is not getting in controller.how can we pass the value in the post to the controller using href tag
In CodeIgniter, POST data isn't passed through as variables into the controller function. You'd instead need to use the input library. You can then use $this->input->post() to get POST data:
$data['date'] = $this->input->post('attendance_date');
Using href tag you don't get data in the post, but you can get the data using a segment like this:
public function reject1()
{
$data['date']=$this->uri->segment(3);
var_dump($data['date']);
$data['modal_subview'] = $this->load->view('admin/engineer_attendance_confirmation/attendance_confirmation_modal',$data,FALSE);
$this->load->view('admin/_layout_modal', $data);
}

How to create pagination with letters using codeigniter

Agent controller:
public function index() {
if (!empty($_SESSION['admin'])) {
$data = array(
'page_title' => 'Agent',
'page_name' => 'agent/index',
'result' => $this->agent_model->list_all()
);
$this->load->view('template', $data);
} else {
redirect('login');
}
}
Agent model:
public function list_all() {
$data = 'agent.id,agent.name,agent.mobile,agent.vehicle,agent.address,agent.img_url,agent.category,agent.status,agent.login_status,vehicle.id AS vehicle_id,vehicle.name AS vehicle_name';
$this->db->select($data);
$this->db->from('agent');
$this->db->join('vehicle', 'agent.vehicle=vehicle.id');
return $this->db->get()->result_array();
}
View:
<?php foreach ($result as $value): ?>
<div class="col-md-4 col-sm-4 col-xs-12 profile_details">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<p><i class="fa fa-user"></i> Name: <?= $value['name']; ?></p>
<ul class="list-unstyled">
<li><i class="fa fa-building"></i> Vehicle: <?= $value['vehicle_name']; ?></li>
<li><i class="fa fa-phone"></i> Mobile: <?= $value['mobile']; ?> </li><br/>
<div class="onoffswitch">
<input type="hidden" value="<?= $value["id"]; ?>"/>
<input type="checkbox" class="js-switch"
<?php if ($value['status'] == 1) {
echo "checked";
} ?>>
</div>
</ul>
</div>
<div class="right col-xs-5 text-center">
<img src="/<?= $value['img_url']; ?>" alt="" class="img-circle img-responsive" style="height: 120px; width: 120px;">
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-6 emphasis">
<p class="ratings">
<a>4.0</a>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
</p>
</div>
<div class="col-xs-12 col-sm-6 emphasis btn-group">
<?php if ($value['status'] == 1): ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php else: ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php endif; ?>
<a href="<?= base_url("agent/detail/{$value['id']}"); ?>" class="btn btn-primary btn-xs">
<i class="fa fa-user"> </i> View Profile </a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Below Screenshot:
Screenshot
MY Question: How to create pagination with letters in codeigniter.
MY Question: I create agent module and i apply pagination with letters in above Screenshot. so how to apply pagination with letters in above view.

how to validate a field in tab?

I need that the customer field is required, if it is empty when pressing the continue button, this not must allow continue to next step and it then should appear a message indicating that the field is empty and need be completed.
Please, i need a help or advice about how to could make the validation.
Using boostrap.
<ul class="nav nav-pills nav-justified" id="NotTab">
<li class="active disabledTab">1. <?php echo $tab_customer; ?></li>
<li class="disabled disabledTab">2. <?php echo $tab_payment; ?></li>
</ul>
<div id="tab-customer" class="tab-pane active">
<div class="control-group">
<label class="control-label" style="color: #F00;"><b><?php echo $entry_customer; ?></b></label>
<div class="controls">
<input type="text" name="customer" value="<?php echo $customer; ?>" class="span3" onclick="this.select();">
<input type="hidden" name="customer_id" value="<?php echo $customer_id; ?>">
<input type="hidden" name="customer_group_id" value="<?php echo $customer_group_id; ?>">
</div></div>
<div class="form-actions">
<button class="btn btn-primary prevtab" type="button" onclick="return showNext()"><span class="glyphicon glyphicon-arrow-right"></span> Next </button></div>
</div>
<script>
var $tabs = $('#NotTab li');
function showPrev() {
$tabs.filter('.active').prev('li').removeClass("disabled");
$tabs.filter('.active').prev('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");
})
}
function showNext() {
$tabs.filter('.active').next('li').removeClass("disabled");
$tabs.filter('.active').next('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");;
})
}
</script>
Thanks.
You can use a simple check, to check if the input is empty.
if( !$('[name=customer]').val() ) {
alert('Input is empty');
return;
}

how to handle Trying to get property of non-object error in laravel?

I am deleting item from cart and after deleting i am displaying fresh result. but all item from cart table is delete i am getting this error
Trying to get property of non-object (View:
D:\xampp\htdocs\avitra\resources\views\ordersummary.blade.php)
for following query. When all item is removed from cart & it display then it can not get any record from cart table so it return null value and getting above error? How can i handle this error in laravel?
$getCartResult=DB::table('product_details')
->join('cart','cart.product_id','=','product_details.product_id')
->join('subcategory','product_details.sub_id','=','subcategory.sub_id')
->select('subcategory.image','subcategory.name_of_subcategory','product_details.*','cart.*')
->where('cart.user_id',$userid)
->get();
blade file:
<?php $getCartResult=DB::table('product_details')
->join('cart','cart.product_id','=','product_details.product_id')
->join('subcategory','product_details.sub_id','=','subcategory.sub_id')
->select('subcategory.image','subcategory.name_of_subcategory','product_details.*','cart.*')
->where('cart.user_id',$userid)
->get();
?>
<?php
if (!empty($getCartResult)) {
?>
<div class="card-body cart_show" style="overflow-y: scroll;height: 300px;display:none;">
#foreach($getCartResult as $v_contents)
<div class="row">
<div class="col-sm-3 mt-3">
<div>
<img src="{{asset('images/'.$v_contents->image)}}" class="img-fluid">
</div>
<center>
<div class="input-group mt-2" style="width:100px">
<button type="button" class="cart-btn btn-default btn-number cart_qtyminus" data-type="minus" data-id="<?php echo $v_contents->cart_id;?>" data-value="<?php echo $v_contents->product_id;?>">
<span class="fa fa-minus cart-fa"></span>
</button>
<!-- <input type="text" name="cart_qty" class="form-control input-number" value="{{$v_contents->qty}}" min="1" max="10"> -->
<span class="cart_quantity " style="border: 1px solid;height: 30px;width:30px;"><?php echo $v_contents->qty; ?></span>
<button type="button" class="cart-btn btn-default btn-number cart_qtyplus" data-type="plus" data-id="<?php echo $v_contents->cart_id;?>" data-value="<?php echo $v_contents->product_id;?>">
<span class="fa fa-plus cart-fa"></span>
</button>
</div>
</center>
</div>
<div class="col-sm-5 mt-3">
<div>
<span><b>{{$v_contents->name_of_subcategory}}</b></span>
</div>
<div class="mt-2">
<span>Seller : Avitra Ayurved</span>
</div>
<?php $subtotal=$v_contents->discount_price*$v_contents->qty; ?>
<div class="mt-2">
Price :<span class="cart_subtotal"><?php echo $subtotal; ?></span>
</div>
<div class="mt-2">
<span><a class="btn btn-sm mt-3 cart_delete" data-id="<?php echo $v_contents->cart_id;?>"><span style="color: #FBA842;"><b>REMOVE</b></span></a></span>
</div>
</div>
<div class="col-sm-4">
<div class="mt-2">
<span>Delivery by Fri Jan 24 | Free</span>
</div>
</div>
</div><hr>
#endforeach
<div>
<span style="float: right;"><button class="btn btn-sm continue cart_payment_show"><span><b>CONTINUE</b></span></button></span>
</div>
</div>
<?php } ?>
You are getting this error because your query is not returning any result and your are trying to access it's property something like $getCartResult->id.
To resolve this you can check if item exists or not using if condition on your blade template for e.g
#if(!empty($getCartResult))
// your code
#endif
I think the problem is that you are trying to access a row that has been deleted. Check the query that you are returning after deleting an item.

Resources