1

I am creating a plugin for wordpress and I want to manage the curriculum of an Institute. I use fullcalendar in order to display the records from the database, using json. The problem is that I want to create edit and delete buttons on every event (simple links). I try to send html code with json, but I get the html tags as text in the browser page.

Is there a way to add working html to my json?

<?php
//json response view lessons
add_action('wp_ajax_utt_json_calendar','utt_json_calendar');
function utt_json_calendar(){
    global $wpdb;
    $viewType = $_POST['viewType'];
    $viewFilter = $_POST['viewFilter'];
    $lessonsTable = $wpdb->prefix."utt_lessons";
    $lessons = $wpdb->get_results("SELECT * FROM $lessonsTable WHERE classroomID=$viewFilter;");
    $jsonResponse = array();
    foreach($lessons as $lesson){
        $result[title] = $lesson->lessonID."<a href='#'>asd</a>";
        $result[start] = $lesson->datetime;
        array_push($jsonResponse,$result);
    }
    echo json_encode($jsonResponse);
    die();
}
?>
Alex Salauyou
  • 14,185
  • 5
  • 45
  • 67
  • is it a problem with all tags including your asd link? You can undo htmlentities -> http://stackoverflow.com/questions/5796718/html-entity-decode – RightClick Apr 07 '15 at 14:23
  • this link is the problem. I ask what can I do from php because the callendar plugin uses this json. – Antony Roussos Apr 07 '15 at 14:35
  • There are options with the `json_encode` function, like `json_encode($jsonResponse, JSON_UNESCAPED_UNICODE)` so you may be able to retain your tags by editing that line. I think you might be better off adding more fields to your json output, for the url and link text, and then editing the javascript to put those fields together. My gut says you're going to need to edit some javascript. If you post the actual output we'd have more to go on. – RightClick Apr 07 '15 at 15:20

1 Answers1

0

Fullcalendar queries that php script and expects text for event.title.

If you want to add links to your events, you need to do this in your FullCalendar options (Javascript).

The FullCalendar option you are looking for is eventRender. It should look something like:

eventRender: function(event, element) {
    element.find('.fc-title').append($("<a href='#'>"+event.editlink+"</a>"));
}

It'll look like this fiddle.

And in your PHP, add the property editLink (or whatever you want to name it) to your returned JSON:

foreach($lessons as $lesson){
    $result[title] = $lesson->lessonID;
    $result[start] = $lesson->datetime;
    $result[editLink] = "asd"; //you could use HTML here but it's better in JS
    array_push($jsonResponse,$result);
}

There really isn't any way to do what you want only in PHP since you have to modify the FullCalendar options (which has to be done in JS) .

DanielST
  • 13,783
  • 7
  • 42
  • 65