0
votes

I am using codeigniter and mysql for web development. I have also used a rich-text editor called tinymce editor. My problem is I have applied the text-editor in a textarea. When I applied header and paragraph tags and etc its all okay but when I used to "center" the text it used the "style" tag of css, like style="text-align:center;" but when I insert it to database it does not include the double quotes "" the thing it will insert is only the style= and it will not include the "" and inside it.

The code below is used to insert data from the form including the textarea that was applied with the tinymce text-editor.

$("#send_email").click(function()
   {


    $("#myModal_loader").modal('show');
    var email_add = $("#email").val();
    var email_subject = $("#email_subject").val();
    var email_message = tinymce.get('email_message').getContent();


    var postData   = {
                      'email_add':email_add,
                      'email_subject':email_subject,
                      'email_message':email_message
                    };

    $.ajax({
        type: "POST",
        url: "<?php echo base_url();?>students/send_email",
        dataType: 'json',
        data: postData,
        success: function(data)
        {
        $("#myModal_loader").modal('hide');
        $("#myModal_confirm").modal('show');

        $("#email_subject").val("");
        $("#email_message").val("");

        console.log();


        }



    });
   $("html, body").animate({ scrollTop: 0 }, 600);

   return false;

    });
    });
    </script>

controller

      $this->course_booking_model->insert_email_data
      ($stored_email,$tennant_email,$email_subject,$email_message); 

model

    function insert_email_data($email_add,$tennant_email,$email_subject,$email_message)         {

  for($i=0;$i<count($email_add);$i++){

  $data = array(
     'email_add'     => $email_add[$i],
     'tennant_email' => $tennant_email,
     'email_subject' => $email_subject,
     'email_message' => $email_message
     );


        $this->db->set('time_sent','NOW()',FALSE);
        $this->db->insert('email', $data);
              }

               }
2
which field is the issue ? email_message? - trrrrrrm
the email message is the issue here because it has html tags and css inline styling which contains double quotes like style="text-align:center". the quotes after the equal sign is not read. - Ferdinand Balbin
check my answer below. - trrrrrrm

2 Answers

2
votes

CI documentation : http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert

$this->db->insert();
Note: All values are escaped automatically producing safer queries.

you need to use

$this->db->set('field', $field_value,FALSE); //FALSE will disable the automatic escaping. 
0
votes

The problem in here is that the formatted value from the textarea being passed from view to controller using ajax is that it does not read all the html tags because it escapes the double quotation in the codes, does passing incomplete html tags.

What I did was before the formatted value will be passed I removed the double quotes and replaced it using the code below.

var new_message = email_message.replace(/"/g, '\'');

and it solved the problem.