[development] a "form_initialize" function? (was "converting a module from Drupal 5 to Drupal 6")
yi yang
yang_yi_cn at yahoo.com
Thu Jan 22 00:00:05 UTC 2009
I'll do
//drupal_get_form('my_form');
function my_form() {
if (everything_is_ok()) {
$form = ...
...
return $form;
}
else {
drupal_set_message("something bad happened.");
return array();
}
}
--- On Wed, 1/21/09, Chris Johnson <cxjohnson at gmail.com> wrote:
From: Chris Johnson <cxjohnson at gmail.com>
Subject: Re: [development] a "form_initialize" function? (was "converting a module from Drupal 5 to Drupal 6")
To: development at drupal.org
Date: Wednesday, January 21, 2009, 3:40 PM
There has to be a better solution than a form_initialize() hook. This
is not criticism directed at you, Sheryl. But I think you've got a
use case that should be addressed, assuming there is not an existing
way to do it. I may well be ignorant of the proper, Drupal-ish way of
handling this situation.
..chris
On Wed, Jan 21, 2009 at 4:12 PM, Sheryl (Permutations Software)
<sheryl at permutations.com> wrote:
> I figured out what the module code was trying to do by creating the error.
> It's actually not well implemented even in Drupal 5, but I don't
know if
> there is a function in Drupal to handle the case.
>
> When the administration form for the module is first loaded, the code
checks
> to see if the module has been correctly installed. If it hasn't, it
displays
> an error message at the top of the form. It attributes the error to the
> submit button just as a convenience. But the user still can see and submit
> the form. Ideally, there would be a form initialization function that
> checked that all was well before the form was even displayed. If all was
not
> well, the user would see the error message, but no admin form.
>
> I don't see a _form_initialize function anywhere in Drupal. Is it
there
> somewhere and I missed it? If not, it might be a good thing to add.
>
> In the meantime, how do I get the name of the submit button so I can use
the
> same technique the module is currently using, but rewritten for Drupal 6?
> The button is not explicitly defined anywhere in the code - it must be
using
> defaults. Also, according to the Drupal 6 docs, the name for buttons
> assigned by the system is 'op' - suggesting that the existing code
is
> already correct:
>
> http://api.drupal.org/api/file/developer/topics/forms_api_reference.html
>
> The following is a list of default values which do not need to be set
(found
> in system_elements):
>
> button
> #name = 'op'
> #button_type = 'submit'
> #executes_submit_callback = FALSE
> #ahah['event'] = 'click'
> -------------------------------------
>
> Thus this statement is exactly correct for what I want to do, even in
Drupal
> 6:
>
> form_set_error('op', 'error text');
>
> Am I missing something here?
>
>
>
> -----Original Message-----
> From: development-bounces at drupal.org
[mailto:development-bounces at drupal.org]
> On Behalf Of Jakob Petsovits
> Sent: Wednesday, January 21, 2009 2:09 PM
> To: development at drupal.org
> Subject: Re: [development] converting a module from Drupal 5 to Drupal 6
>
> On Wednesday, 21. January 2009, Steven Jones wrote:
>> Use form_set_error
>> (http://api.drupal.org/api/function/form_set_error/6) and call it with
>> the first parameter as 'NULL', then the error will be set on
the form
>> as a whole, not an individual element.
>
> form_set_error() encloses the error assignment in this if-condition:
>
> if (isset($name) && !isset($form[$name])) {
> (...set the form error...)
> }
>
> which means when the first parameter ($name) is NULL then no error will be
> set.
> It seems you need to set the error for any of your form elements,
presumably
>
> the submit button in your case was used because the submit button was the
> only
> element that's remotely suitable for that error.
>
> You might use the actual submit button as error target in Drupal 6 (...I
> think
> that should work) by doing a form_set_error('mybuttonname',
t('message')) or
> -
> alternatively, same effect - form_error($form['mybuttonname'],
> t('message')).
>
> Cheers,
> Jakob
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20090121/7e933b35/attachment.htm
More information about the development
mailing list