Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: mks on August 01, 2012, 05:16:54 AM

Title: formincomplete: problem with my custom plugin
Post by: mks on August 01, 2012, 05:16:54 AM
Hi.

I have been customizing RC for a big university and I've stumbled upon a problem that I can't seem to get rid of.

So the reason for this plugin is that we need to lock down the ability to edit the name field in the identity form. It gets overwritten after every logon anyway.

The plugin I made is very simple and works as intended. However, as a consequence, every time I try to edit any identity field, I get the formincomplete error (The form was not completely filled out).

<?php

/*      Lock the name field in the identity edit form.
 * 
 *      @author: Markus Arro    
 *      @version: 31.07.2012
 */

class identity_disable_name extends rcube_plugin
{
    public 
$task 'settings';

    function 
init()
    {
        
$this->add_hook('identity_form', array($this'disable_name'));
    }


function 
disable_name($form) {

        
$form['form']['addressing']['content']['name']['disabled'] = true;
        
$form['form']['addressing']['content']['name']['class'] = 'disabled';

        return 
$form;

        }
}


The same problem occurs if I make the change directly to program/steps/settings/edit_identity.inc.

I'm guessing the cause is the input validation in program/steps/settings/save_identity.inc:
// check input
if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3))
{
  $OUTPUT->show_message('formincomplete', 'warning');
  rcmail_overwrite_action('edit-identity');
  return;
}


However, I don't know how to get around it. Ideally, I would like to refrain from making changes to the RC code and implement any new functionality with plugins, as this will simplify future upgrades.

I'd very much appreciate any advice You can give me.
Title: Re: formincomplete: problem with my custom plugin
Post by: SKaero on August 01, 2012, 08:54:43 PM
You'll need to add a function for hooks identity_update and probably identity_create to validate the data.
Title: Re: formincomplete: problem with my custom plugin
Post by: mks on August 02, 2012, 05:07:26 AM
Sorry, I'm a total beginner in PHP and don't quite understand what You mean by that. Can you be more specific?

Also, if I understand correctly, the hook identity_update occurs later in the file save_identity.inc and isn't built to modify the $_POST array anyway.

I also tried removing empty($_POST['_name']) from the input validation and it worked. In fact, it seem's to me that the whole section is unnecessary in my case because the identities_level is set to 3 and the names are copied from a database after every logon by another plugin.

Anyway, if You know of a way to bypass this input validation from whithin a plugin, or modify the $_POST array, let me know. But for now, I'll just comment out the whole section.
Title: Re: formincomplete: problem with my custom plugin
Post by: JohnDoh on August 03, 2012, 07:50:39 AM
hi. i think disabled form elements are not submitted. have you considered setting it as readonly rather than disabled?
Title: Re: formincomplete: problem with my custom plugin
Post by: mks on August 03, 2012, 08:41:12 AM
Quote from: JohnDoh on August 03, 2012, 07:50:39 AM
hi. i think disabled form elements are not submitted. have you considered setting it as readonly rather than disabled?

Yes, that works. Didn't know about the readonly.

Thank you! :)