[dev] Question to Horde Form Actions

Ralf Lang lang at b1-systems.de
Sun Jul 15 10:07:42 UTC 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Karim,

Am 14.07.2012 23:11, schrieb Karim Geiger:
> On 07/11/2012 09:45 PM, Jan Schneider wrote:
>> 
>> Zitat von Karim Geiger <geiger at b1-systems.de>:
>> 
>>> On 07/10/2012 12:11 PM, Jan Schneider wrote:
>>>> Nag_Form_Task, Whups_Form_Query_PropertyCriterion, 
>>>> Whups_Form_Ticket_Edit, Horde_Config_Form
>>> Sorry for my late reply.. Well that helped a bit but I don't
>>> want to refresh the whole page. I just want to add a new field.
>>> I did a bit research and found that example:


> Sorry but that doesn't help me a bit.. could you please send me an 
> existing code-example so I can see the structure of adding,
> reloading and creating forms.

This is taken from /horde/whups/lib/Form/Ticket/Edit.php
See whole file for more context.

What happens here? We're viewing the code where you can give a comment
to a ticket. In whups, you can have template replies to choose from.

                case 'comment':
                    $cvar = &$this->addVariable(
                        _("Comment"), 'newcomment', 'longtext', false);

                    /* Form replies. */
                    try {
                        $replies = Whups::permissionsFilter(
                            $whups_driver->getReplies($type), 'reply');
                    } catch (Whups_Exception $e) {
                        $replies = array();
                    }


The code above fetches template replies from database (if any exist).
Now we want to show the dropdown with replies only if we have template
replies in database (the count of $replies is not 0 or false)

                    if (count($replies)) {
                        $params = array();
                        foreach ($replies as $key => $reply) {
                            $params[$key] = $reply['reply_name'];
                        }
                        $rvar = &$this->addVariable(
                            _("Form Reply:"), 'reply', 'enum', false,
false,
                             null, array($params, true));


We fill the params array and add a form reply line to the form which
contains these template replies.


$rvar->setAction(Horde_Form_Action::factory('reload'));
                        if ($vars->get('reply')) {
                            $reply = $vars->get('newcomment');
                            if (strlen($reply)) {
                                $reply .= "\n\n";
                            }
                            $reply .=
$replies[$vars->get('reply')]['reply_text'];
                            $vars->set('newcomment', $reply);
                            $vars->remove('reply');
                        }
                    }


This part attaches a reload action to selecting any of these fields.
When the user selects any form reply, the form is reloaded and the
answer textbox is prefilled with the template reply.


The rest of the code checks for permissions to set for a comment. It
is not important for your problem but worth reading.


                    /* Comment permissions. */
                    $groups =
$GLOBALS['injector']->getInstance('Horde_Group');
                    $mygroups =
$groups->listGroups($GLOBALS['registry']->getAuth());
                    if ($mygroups) {
                        foreach (array_keys($mygroups) as $gid) {
                            $grouplist[$gid] = $groups->getName($gid,
true);
                        }
                        asort($grouplist);
                        $grouplist = array(0 => _("This comment is
visible to everyone")) + $grouplist;
                        $this->addVariable(
                            _("Make this comment visible only to
members of a group?"), 'group',
                            'enum', false, false, null,
array($grouplist));
                    }
                    break;




- -- 
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: lang at b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAClm4ACgkQCs1dsHJ/X7DC2wCgn5D9kfWj0YBThMX+jZ60Hy9H
3/UAnii4/onDco04SLwamRhBmpQu9a6L
=RIDW
-----END PGP SIGNATURE-----


More information about the dev mailing list