How to build in checkbox into the form?
Posted: Fri Jul 14, 2006 10:30 am
Hi, i need to build in the checkbox in the post message form, how can i make it with my plugin ?
Thanks
Thanks
User and developer community
https://board.s9y.org/
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.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
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;
}
}
}
see the code:garvinhicking wrote:Hi!
Where do you want to print that, and "when"?
Regards,
Garvin
Code: Select all
case 'backend_publish':
if (isset($serendipity['POST']['mycheckbox'])) {
// My text here
}
And can I print it without textbox, as in a new page ?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
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) "" }