Hello,
I don't know about PHP but I do so many experiments to fix it. So I found the code and implement it on my site and it's working perfectly. But have an issue. The code is for the input field and also user can add more input fields by pressing the + button. So I need a TextArea box only with the visual editor, no need for + button as well. Can you help me with this, please?
Controller:
Code:
$objectives= array();
if (isset($post['objective_descriptions'])) {
for ($i = 0; $i < count($post['objective_descriptions']); $i++) {
if ($post['objective_descriptions'][$i] != "") {
array_push($objectives, array('description' => $post['objective_descriptions'][$i],
'cv_id' => $cv_id
));
}
}
$this->cv_objective_model->insert($objectives);
}
View:
Code:
<div class="divider" > </div>
<?php if(count($objectives) > 0) :?>
<h4 class="heading">OBJECTIVE</h4>
<table style="width: 100%;" class="text">
<?php foreach($objectives as $a) :?>
<tr>
<td><?=$a->description?></td>
</tr>
<?php endforeach; ?>
</table>
<div class="divider"></div>
<?php endif; ?>
Add:
Code:
<div class="cv-section-title">
<p class="font-weight-600 text-16">Objective</p>
</div>
<div class="form-row">
<div class="col-1">
<!--just to align labels-->
</div>
</div>
<?php if($update_cv):?>
<?php foreach($cv_objectives as $a): ?>
<div class="form-row">
<div class="form-group col">
<textarea type="text" name="objective_descriptions[]" placeholder="Objective" class="form-control" id="cv_objective" rows="8" cols="80"><?php echo $a->description; ?></textarea>
<input type="text" placeholder="Objective" class="form-control obj-textarea" value="<?=$a->description?>" name="objective_descriptions[]" />
</div>
<div class="form-group col-1 add-award-container" onclick="onRemoveAwardClicked(this)">
<div class="add-info">
<button type="button" class="btn btn-default btn-lg" ><i class="fa fa-minus text-danger"></i></button>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<? endif ;?>
<div class="form-row">
<div class="form-group col">
<textarea type="text" name="objective_descriptions[]" placeholder="Objective" class="form-control" rows="8" id="cv_objective" cols="80"><?php echo $a->description; ?></textarea>
<input type="text" placeholder="Objective" class="form-control obj-textarea" name="objective_descriptions[]" />
</div>
<div class="form-group col-1 add-award-container" onclick="onAddAwardClicked(this)">
<div class="add-info">
<button type="button" class="btn btn-default btn-lg" ><i class="fa fa-plus text-success"></i></button>
</div>
</div>
</div>
Model:
Code:
<?php
class Cv_objective_model extends CI_Model
{
public function __construct()
{
$this->load->database();
parent::__construct();
}
public function getByCvId($cv_id)
{
$this->db->from('cv_objective');
$this->db->where('cv_id', $cv_id);
$data = $this->db->get()->result();
return $data;
}
public function insert($data)
{
if(count($data) == 0){
return;
}
$this->db->insert_batch('cv_objective', $data);
}
public function removeByCvId($cv_id){
$this->db->delete('cv_objective', array('cv_id'=>$cv_id));
}
}