Roundcube Community Forum

 

Roundcube "Button" for post data?

Started by Lambda89, April 12, 2010, 09:44:14 AM

Previous topic - Next topic

Lambda89

Just a quick question. Is the roundcube: button require to be able to send post-data from a form correctly? I've been working with a normal for a plugin so far, and no matter what I've tried, there always seem to be no data in the $_POST-array.

If the answer is "No", I'd be glad to post my code if someone would be nice enough to help me debug it.

Best regards

rosali

Did you really have the slash behind the opening tag or is this just a typo?
Regards,
Rosali

Lambda89

#2
It's a typo. My bad.

The biggest issue for me with is that it can't be loaded dynamically. I want to print a form via an AJAX-request, and I would preferrably avoid to load a new template into my content-div. So I would *really* like to use an "ordinary" submit for this particular task.

Lambda89

I'll go ahead and post the code immediately ... not to go ahead of anything, of course.

//Register action in init

$this->register_action('plugin.manageprocmail_create', array($this, 'createFilter'));

//createFilter-function

   function createFilter()
   {
      $rcmail = rcmail::get_instance();
      
      $filterParams =   array(
               get_input_value('_filter_name', RCUBE_INPUT_POST),
          get_input_value('_messages', RCUBE_INPUT_POST),
          get_input_value('_object', RCUBE_INPUT_POST),
          get_input_value('_condition', RCUBE_INPUT_POST),
          get_input_value('_parameter', RCUBE_INPUT_POST),
          get_input_value('_rule', RCUBE_INPUT_POST),
          get_input_value('_location', RCUBE_INPUT_POST)
         );
            
   $result = $this->createNewFilter($filterParams);
   $rcmail->output->command('plugin.manageprocmail_create', array('result' => $result));
   }

//The HTML, returned from a php-function called printFilterForm().





//The Javascript/jQuery

      rcmail.addEventListener('plugin.manageprocmail_new', printForm);
      rcmail.register_command('plugin.manageprocmail_new', function() { rcmail.http_post('plugin.manageprocmail_new', '&_action=plugin.manageprocmail_new') }, true);
      
      function printForm (response) {
         $('#filter-box').html(response.a_form);
      }

I really appreciate any help with this, cause' I'm quite at a loss right now. :confused:

rosali

What results here?


$this->add_hook('startup', array($this, 'createFilter'));

.
.
.
function createFilter(){
  $rcmail = rcmail::get_instance();
  if($rcmail->action == 'plugin.manageprocmail_create'){
    print_r($_POST);
    exit;
  }
}
Regards,
Rosali

Lambda89

Sadly, this (print_r($_POST), to be specific) only generates a server-error. I then tried to send just my $_POST back to the JavaScript, to try to print it that way, but this prints nothing. Not even "Array". So, still, somehow my $_POST variable is emptied somewhere through the script, or it's never sent from the form at all.

I am very appreciative for your help, by the way. I'm pretty much new to writing roundcube plugins, and the API for it can be a bit freightening sometimes (even if it's totally kickass).

Best regards

Lambda89

This is the JavaScript for posting the form, by the way. Could it be something in it that interferes with the $_POST-variable? Hehe, my head is going numb here. Been trying a tonne of different solutions, but nothing seems to work. :D

The JS:
//Edit: The separation in the create is because of the formatting of the forum, it's not like that in the code.

      rcmail.register_button('plugin.manageprocmail', 'button', 'link');
      rcmail.addEventListener('plugin.manageprocmail_create', confirmCreate);
      function confirmCreate (response) {
         $('#filter-box').html(response.result);
      }
      
      $('#new_filter').live('click', function(){
         rcmail.http_post('plugin.manageprocmail_create', '&_action=plugin.manageprocmail_create');
         
         printInit();
         
         return false;
      });

rosali

I'm not sure, but the leading ampersand in the post date url looks strange to me. You can debug $_POST submitted by a Roundcube AJAX request by:

write_log('mydebug',$_POST);

This will create the file mydebug in the logs folder.
Regards,
Rosali

Lambda89

This is what I get in return ...

[13-Apr-2010 23:13:08 +0200]: array (
  '_action' => 'plugin.manageprocmail_create',
  '_remote' => '1',
)

I have no clue how to interpret it though ...

rosali

Well, $_POST is not empty! So handle the post data according to your needs. How to advice how to process valid data in your plugin ?!?
Regards,
Rosali

Lambda89

Thank you for going out of your way for my sake, but I figured out what I was doing wrong. The solution, or rather, my misconception was that the post-data automagically just followed my AJAX-request along. It does not. And the solution is to use var id = $('#id').val(); to get the values, and then pass them with their proper names to the request. For instance: '&_id='+id

Thank you again for taking your time to help me think things through.

Best regards(!)