CodeIgniter Forums

Full Version: Need to add Textarea with Visual Editor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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));
    }
}
@xaibi,

What specific text editor are you using?
Its plain text editor and my developer quit the job on my project. So i am trying my self to do some stuff. So i shared the code which is working good. I need to know i how can make textarea instead of input field.
@xaibi,

You should be able to specify the field type that the editor is attached to somewhere in the javascript code that is on the page. That is the reason why I asked you specifically what was the name of the editor (i.e. https://stackoverflow.com/questions/1921...l-textarea ) used because it would make it easier to figure out how to configure it to work with a textarea.
Ok, i will check it and let you know, for a time being can you fix only textarea.
I did to make textarea and its working but if there is no data in textarea then I textarea get hide.

See screenshot: https://prnt.sc/pph5o3
@xaibi,

Did you set the size for the textarea?
Hello, no i did not should i write this (height="40px")

Will this work?
(10-29-2019, 11:38 AM)xaibi Wrote: [ -> ]Hello, no i did not should i write this (height="40px")

Will this work?

No, for textarea you must set the attributes rows and or cols.  You could also set a default value  called placeholder.

reference: https://www.w3schools.com/tags/tag_textarea.asp
I think he is talking about using Visual Editor which is a WordPress editor.

Correct me if I' am wrong.
Pages: 1 2