How to build in checkbox into the form?

Discussion corner for Developers of Serendipity.
Post Reply
loncaster_ukraine
Regular
Posts: 5
Joined: Fri Jul 14, 2006 10:25 am

How to build in checkbox into the form?

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to build in checkbox into the form?

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
loncaster_ukraine
Regular
Posts: 5
Joined: Fri Jul 14, 2006 10:25 am

Re: How to build in checkbox into the form?

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to build in checkbox into the form?

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
loncaster_ukraine
Regular
Posts: 5
Joined: Fri Jul 14, 2006 10:25 am

Post 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?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

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

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
loncaster_ukraine
Regular
Posts: 5
Joined: Fri Jul 14, 2006 10:25 am

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
loncaster_ukraine
Regular
Posts: 5
Joined: Fri Jul 14, 2006 10:25 am

Post 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) "" } 
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Is your checkbox showing up in the entry form?
Judebert
---
Website | Wishlist | PayPal
Post Reply