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