Author Topic: Roundcube "Button" for post data?  (Read 8559 times)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« on: April 12, 2010, 09:44:14 AM »
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
« Last Edit: April 13, 2010, 02:36:21 AM by Lambda89 »

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Roundcube "Button" for post data?
« Reply #1 on: April 13, 2010, 12:37:21 AM »
Did you really have the slash behind the opening tag or is this just a typo?
Regards,
Rosali
__________________
MyRoundcube Project (commercial)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #2 on: April 13, 2010, 02:35:54 AM »
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.
« Last Edit: April 13, 2010, 02:59:50 AM by Lambda89 »

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #3 on: April 13, 2010, 03:43:02 AM »
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:

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Roundcube "Button" for post data?
« Reply #4 on: April 13, 2010, 05:10:11 AM »
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
__________________
MyRoundcube Project (commercial)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #5 on: April 13, 2010, 07:24:42 AM »
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

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #6 on: April 13, 2010, 09:28:21 AM »
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;
      });

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Roundcube "Button" for post data?
« Reply #7 on: April 13, 2010, 03:01:57 PM »
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
__________________
MyRoundcube Project (commercial)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #8 on: April 13, 2010, 05:14:24 PM »
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 ...

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Roundcube "Button" for post data?
« Reply #9 on: April 13, 2010, 06:33:01 PM »
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
__________________
MyRoundcube Project (commercial)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Roundcube "Button" for post data?
« Reply #10 on: April 13, 2010, 06:39:43 PM »
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(!)