Page 1 of 1

How to build in checkbox into the form?

Posted: Fri Jul 14, 2006 10:30 am
by loncaster_ukraine
Hi, i need to build in the checkbox in the post message form, how can i make it with my plugin ?

Thanks

Re: How to build in checkbox into the form?

Posted: Fri Jul 14, 2006 12:11 pm
by garvinhicking
Hi!

You can hook into the 'backend_display' event, like the serendipity_event_entryproperties plugin does for example.

If you tell us more of what you want to do, I might be able to help you even more. ;)

Best regards,
Garvin

Re: How to build in checkbox into the form?

Posted: Fri Jul 14, 2006 2:35 pm
by loncaster_ukraine
garvinhicking wrote:Hi!

You can hook into the 'backend_display' event, like the serendipity_event_entryproperties plugin does for example.

If you tell us more of what you want to do, I might be able to help you even more. ;)

Best regards,
Garvin
Well, after the posting new message plugin must check if the checkbox in the form was checked ON and then do something with the post content.

By the way, i wanted to ask something: in the WordPress blog the is a hook action "publish post" that executes when the post has been already stored in the database. Does Serendipity have something like this? (It must executes ONLY when the content is stored in DB).

P.S.
sorry for my pure english, but itsn't my native language ..

Thanks for the answers.

Re: How to build in checkbox into the form?

Posted: Fri Jul 14, 2006 3:01 pm
by garvinhicking
Hi!

Yes, you can do that. You should use a plugin like this:

Code: Select all

<?php

class serendipity_event_mycheckbox extends serendipity_event
{
    var $title = 'My Checkbox';

    function introspect(&$propbag)
    {
        global $serendipity;

        $propbag->add('name',          'My checkbox');
        $propbag->add('author',        'Garvin Hicking');
        $propbag->add('version',       '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));

        $propbag->add('event_hooks',    array(
            'backend_publish'                                   => true,
            'backend_display'                                   => true,
        ));
        $propbag->add('groups', array('BACKEND_EDITOR'));
    }

    function generate_content(&$title) {
        $title = $this->title;
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'backend_display':
?>
                    <fieldset style="margin: 5px">
                        <legend>My Checkbox</legend>
                            <input type="checkbox" name="serendipity[mycheckbox]" id="mycheckbox" value="true" />
                                <label title="My Checkbox" for="mycheckbox"> Check me!  </label><br />
                    </fieldset>
<?php
                    return true;
                    break;

                case 'backend_publish':
                    if (isset($serendipity['POST']['mycheckbox'])) {
                        // Perform your action here that should be executed when an entry is published!
                    }

                    return true;
                    break;
            }
        } else {
            return false;
        }
    }
}
The most important thing is the "backend_publish" event hook, there you can execute PHP you want to let happen when you save an entry.

Best regards,
Garvin

Posted: Mon Jul 17, 2006 4:01 pm
by loncaster_ukraine
Thank you a lot! And now I've new questions.

Imaging, that the check box was checked on, so i want to write for example "You've checked it". but I want to print it in the design of the admin panel! How can I do it?

Posted: Mon Jul 17, 2006 4:07 pm
by garvinhicking
Hi!

Where do you want to print that, and "when"?

Regards,
Garvin

Posted: Mon Jul 17, 2006 5:03 pm
by loncaster_ukraine
garvinhicking wrote:Hi!

Where do you want to print that, and "when"?

Regards,
Garvin
see the code:

Code: Select all

case 'backend_publish': 
                    if (isset($serendipity['POST']['mycheckbox'])) { 
                        // My text here
                   } 
I must send the content of the post to the server and print the answer in the design of the admin panel. "My text here" will be raplaced with a answer of the server.

Posted: Mon Jul 17, 2006 5:16 pm
by garvinhicking
Hi!

Ah, you should just check that. The place where it appears is a simple text box, it is formatted with default HTML. Just echo your text and have a look.

Best regards,
Garvin

Posted: Mon Jul 17, 2006 5:21 pm
by loncaster_ukraine
garvinhicking wrote:Hi!

Ah, you should just check that. The place where it appears is a simple text box, it is formatted with default HTML. Just echo your text and have a look.

Best regards,
Garvin
And can I print it without textbox, as in a new page ?


By the way, I can't get acces for my checkbox (((

var_dump($serendipity['POST']);

Code: Select all

array(15) { ["action"]=> string(5) "admin" ["adminModule"]=> string(7) "entries" ["adminAction"]=> string(4) "save" ["id"]=> string(0) "" ["timestamp"]=> string(10) "1153149985" ["preview"]=> string(5) "false" ["token"]=> string(32) "629ece84ce4791cbe160c4a7c3498fa0" ["title"]=> string(0) "" ["isdraft"]=> string(5) "false" ["chk_timestamp"]=> string(10) "1153149985" ["new_timestamp"]=> string(16) "2006-07-17 18:26" ["categories"]=> array(1) { [0]=> string(1) "0" } ["body"]=> string(5) "hello" ["allow_comments"]=> string(4) "true" ["extended"]=> string(0) "" } 

Posted: Thu Jul 20, 2006 7:26 am
by judebert
Is your checkbox showing up in the entry form?