Hello,
I'm just wondering if anyone knows of a good tutorial or example for rendering HTML forms in roundcube with a POST or using AJAX. Or maybe someone can give me a vague rundown on how to accomplish this with the Roundcube MVC.
In my main plugin class I have a function that is used to create an 'html_table' and add 'html_radiobuttons' and html::labels but I don't see an option to create a submit button or a form which leads me to belive I'm going about this all wrong. Pehaps all of this should be done in the template file?
Essentially what I want to do is query an LDAP database, grab the current spam setting and select the corresponding radio button. If the user changes the value and hits submit, I need to update LDAP and refresh the screen with the appropriate radio selected.
I've setup the plugin directory structure as follows:
.
├── config.inc.php
├── localization
│ ├── en_US.inc
│ └── fr_FR.inc
├── skins
│ └── classic
│ ├── help.gif
│ ├── spamsettings.css
│ └── templates
│ └── spamsettings.html
└── spam_settings.php
Here is the template source:
<!DOCTYPE html >
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<link rel="stylesheet" type="text/css" href="/settings.css" />
</head>
<body>
<roundcube:include file="/includes/taskbar.html" />
<roundcube:include file="/includes/header.html" />
<div id='spamcontent'>
<roundcube:object name="spamcontrols" id="spamcontrols" />
</div>
</body>
</html
And my Plugin Code:
class spam_settings extends rcube_plugin
{
function init()
{
$rcmail = rcmail::get_instance();
$this->add_texts('localization/', false);
$this->register_task('spamsettings');
$this->register_action('index', array($this, 'configure'));
$this->register_action('post', array($this, 'post'));
$this->add_button(array(
'command' => 'spamsettings',
'class' => 'button-spam',
'classsel' => 'button-spam button-selected',
'innerclass' => 'button-inner',
'label' => 'spam_settings.Spam'
),
'taskbar'
);
$skin = $rcmail->config->get('skin');
$this->include_stylesheet("skins/$skin/spamsettings.css");
}
function configure()
{
$rcmail = rcmail::get_instance();
$rcmail->output->set_pagetitle('Spam Settings');
$rcmail->output->add_handlers(array("spamcontrols" => array($this, "content")));
$rcmail->output->send('spam_settings.spamsettings');
}
function content($attrib) {
$rcmail = rcmail::get_instance();
$current_value = "off";
// HOW DO I MAKE A FORM TO POST OR DO SOME AJAX
$table = new html_table(array('class' => 'test', 'cols' => 3));
$radio = new html_radiobutton();
$table->add_header(null, null);
$table->add_header(null, html::label('head_level', Q($this->gettext('Level'))));
$table->add_header(null, html::label('head_desc', Q($this->gettext('Description'))));
$table->add_row();
$table->add(null, $radio->show($current_value, array("name" => "spamlevel", "value" => "off")));
$table->add(null, html::label('off', Q($this->gettext('Off'))));
$table->add(null, html::label('off_desc', Q($this->gettext('OffDesc'))));
$table->add_row();
$table->add(null, $radio->show($current_value, array("name" => "spamlevel", "value" => "low")));
$table->add(null, html::label('low', Q($this->gettext('Low'))));
$table->add(null, html::label('low_desc', Q($this->gettext('LowDesc'))));
$table->add_row();
$table->add(null, $radio->show($current_value, array("name" => "spamlevel", "value" => "med")));
$table->add(null, html::label('med', Q($this->gettext('Med'))));
$table->add(null, html::label('med_desc', Q($this->gettext('MedDesc'))));
$table->add_row();
$table->add(null, $radio->show($current_value, array("name" => "spamlevel", "value" => "high")));
$table->add(null, html::label('high', Q($this->gettext('High'))));
$table->add(null, html::label('high_desc', Q($this->gettext('HighDesc'))));
$table->add_row();
$table->set_row_attribs(array("colspan" => 3));
// NEED A BUTTON HERE
return $table->show();
Should I move my entire form to the template since pretty much static? If so, how do set the selected radio button on page load without using Javascript (Should be done server side prior to rendering the HTML).
Can I use the localizations in a template?
How and where do I handle the post values?
Your on the right track:
html::tag('form', array());
How do i make use of the <roundcube:object> tag in my template file?
I have tried to place a <roundcube:object name="addresslist" id="contacts-table"> in the template but nothing is rendered to the screen.
Check out the documentation: http://trac.roundcube.net/wiki/Doc_Plugins#Templates
As far as i can tell i have done everything properly. I have other object tags such as <roundcube:object name="pagetitle" /> that are rendering correctly. For some reason the <roundcube:object name="addresslist" id="contacts-table">object is stripped from HTML output.
I just noticed in the documentation the following:
Please note that most objects are only available in certain steps/tempaltes. An object tag will be ignored and replaced by an empty string if it's not available.
I guess I can't use this object at this 'step' and that is why a blank line is outputted.
Is there a document somewhere that lists where each 'object' is available?
Here all the documentation on it: http://trac.roundcube.net/wiki/Doc_SkinML#Contentobjects