0

I am pulling info from my Wordpress database into a dropdown. When an option is selected from the dropdown, a div is populated with a form from another page. The page gets the info from the database based on the dropdown fine. The problem I am having is that wp_editor isn't completely loading. The toolbar is missing, and clicking visual or text does nothing. Any help is appreciated.

Here is my code:

    function event_editevent_page() {
    global $wpdb;
    ?>
    <script>
        function showeditevent(str) {
            var location1 = window.location.href;
            var directoryPath = '<?php echo plugins_url(); ?>';
            //alert(directoryPath);
            if (str == "") {
                document.getElementById("txtEditevent").innerHTML = "";
                return;
            } else {
                if (window.XMLHttpRequest) {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else {
                    // code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        document.getElementById("txtEditevent").innerHTML = this.responseText;
                    }
                };
                xmlhttp.open("GET",directoryPath+"/events/editevent.php?q="+str,true);
                xmlhttp.send();
            }
        }
    </script>
    <?php

    echo "<h2>Edit Event</h2>";


    $sql = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "cmc_events order by date, time");

    ?>
    <form>
        <select name="editevent" id="editevent" onchange="showeditevent(this.value)">
            <option value="">Select Event</option>
            <?php
                foreach ($sql as $event) {
                    $id = $event->id;
                    $title = $event->title;
                    $date = $event->date;
                    $time = $event->time;
                    ?><option value="<?php echo $id; ?>"><?php echo $title . " - " . $date . " - " . $time; ?></option><?php
                }
            ?>
        </select>
    </form>
    <div id="txtEditevent"></div>
    <?php

}

editevent.php

<?php
require_once('../../../wp-load.php');
global $wpdb;

$id = $_GET["q"];

$sql = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "cmc_events where id=$id");

$title = $sql->title;
$date = $sql->date;
$time = $sql->time;
$info = $sql->info;
$filename = $sql->filename; 
$newdate = DateTime::createFromFormat('m-d-Y', $date)->format('Y-m-d');
?>
<div class="wrap">
<form name="editevent" action="" method="post" enctype="multipart/form-data">
<table>
    <tr>
        <th align="right" valign="top">Title:</th>
        <td><input type="text" name="title" placeholder="Title" value="<?php echo $title; ?>" /></td>
    </tr>
    <tr>
        <th align="right" valign="top">Date:</th>
        <td><input type="date" name="newdate" value="<?php echo $newdate; ?>" /></td>
    </tr>
    <tr>
        <th align="right" valign="top">Time:</th>
        <td><input type="time" name="newtime" value="<?php echo $time; ?>" /></td>
    </tr>
    <tr>
        <th align="right" valign="top">File <i>(Optional):</i></th>
        <td><input type="file" name="infofile" id="infofile" accept=".pdf"></td>
    </tr>
    <tr>
        <th align="right" valign="top">Information:</th>
        <td>
            <?php
            $content = $info;
            $editor_id = 'info';
            $settings = array(
                'textarea_name' => 'info',
                'textarea_rows' => 10,
                'tinymce' => array(
                    'width' => 1000
                )
            );

            wp_editor( $content, $editor_id, $settings );
            ?>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center"><input type="submit" name="save_edit_event" value="Save Edit"></td>
    </tr>
</table>
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.