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