开发者

TinyMCE : How to insert snippets in editor which will be replaced by plain PHP?

I want to be able to pick in a select list inside tinyMCE a 'snippet' (for example a contact_form or poll_form) which will be placed in the editor.

example:

My first post is an article talking about animals
#contact_form#

When the row will be displayed the frontend, it'll not output 'contact_form' but it has to be replaced by PHP code which needs to be interpreted <?php include('contact_form') ?> or something like that.

example:

My first post is an article talking about animals
<?php include('contact_form') ?>
// <form name="blabal">
// .....

Have you an idea how to achieve that please ? Thanks

Edit I won't execute the code later, the visitor will just see the form and not the php part. That's why i said that he needs to be interpreted.

How do i add a select list in TinyMCE edi开发者_运维问答tor in order to the admin choose which form he'll be including in the tinyMCE ?


You can assign the content of an included php file using output buffering, then simply switch this using an str_replace().

if(strpos('#contact_form#', $input)) { // Check if we need to first
    ob_start();
    include('contact-form.php');
    $form = ob_get_contents();

    $output = str_replace('#contact_form#', $form, $input);
}

I hope this is what you mean, if you want to input PHP code so you can than execute it later, this would be suicide as your whole input will be executable. Note: I haven't tested this!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜