I'm trying to write a new module, and having some trouble with the forms API. I'm deploying this under Drupal 5. I've been reading the tutorials and documentation for the forms API. A lot of this module is cut and paste from the documentation. I'm able to generate a form properly, and even theme it. It displays properly in my browser. However, when I submit the form, the _submit function isn't called. The code is here: http://phantom.dragonsdawn.net/~gordon/customerportal.module The browser sends the form data via POST, and the web server responds with "200 OK", sending back the form HTML. It doesn't log any errors. I have no idea how to go about debugging Drupal to determine why the _submit function isn't being called. Can anyone give me some pointers?
I wonder if it's because you are missing a final call drupal_render($form) in your theme function? Also a suggestion for simplifying your code, when you build the form change the loop with invoices to while ($invoice = db_fetch_object($invoices)) { $fieldname = 'invoice-' . $invoice->invoice; $form['invoice'][$invoice->invoice] = array( '#type' => 'checkbox', '#title' => $invoice->invoice, '#default_value' => 0, '#cp_data' => array( 'invoice' => $invoice->invoice, 'total_due' => $invoice->total_due, 'date_due' => $invoice->date_due, 'status' => $invoice->status ) ); } $form['invoice']['#tree'] = TRUE; Then instead of looping through the whole form/form values you can loop through invoice and have the invoice for the key getting rid of the need for string manipulation. Some like foreach ($form['invoice] as $invoice => $element) { or foreach ($form_values['invoice] as $name => $value) { nevets
Steve Ringwood wrote:
I wonder if it's because you are missing a final call drupal_render($form) in your theme function?
That's exactly it. I really appreciate everyone who pointed that out. The example in the documentation does exactly that, I simply didn't understand its significance. Thanks.
Also a suggestion for simplifying your code, when you build the form change the loop with invoices to
while ($invoice = db_fetch_object($invoices)) { $fieldname = 'invoice-' . $invoice->invoice; $form['invoice'][$invoice->invoice] = array( ... $form['invoice']['#tree'] = TRUE;
I took your advice here, too. It really only saved one line of string manipulation, since the theme still has to skip over elements that start with '#', but at least the submit() function is clearer. Plus I understand the "#tree" thing a little better, which is good. :)
Simplest solution is to directly assign the submit function to the form. $form['#submit'][] = 'customerportal_form_submit'; On Tue, Mar 17, 2009 at 10:19 PM, Gordon Messmer <yinyang@eburg.com> wrote:
I'm trying to write a new module, and having some trouble with the forms API. I'm deploying this under Drupal 5. I've been reading the tutorials and documentation for the forms API. A lot of this module is cut and paste from the documentation.
I'm able to generate a form properly, and even theme it. It displays properly in my browser. However, when I submit the form, the _submit function isn't called. The code is here:
The browser sends the form data via POST, and the web server responds with "200 OK", sending back the form HTML. It doesn't log any errors. I have no idea how to go about debugging Drupal to determine why the _submit function isn't being called. Can anyone give me some pointers?
I have to remember the solution, I suppose. I'm a module guy, not a theme guy... On Wed, Mar 18, 2009 at 1:32 AM, Gordon Messmer <yinyang@eburg.com> wrote:
Earl Dunovant wrote:
Simplest solution is to directly assign the submit function to the form. $form['#submit'][] = 'customerportal_form_submit';
I had actually tried that at one point. :)
Thanks.
2009/3/17 Gordon Messmer <yinyang@eburg.com>:
I'm trying to write a new module, and having some trouble with the forms API. I'm deploying this under Drupal 5. I've been reading the tutorials and documentation for the forms API. A lot of this module is cut and paste from the documentation.
I'm able to generate a form properly, and even theme it. It displays properly in my browser. However, when I submit the form, the _submit function isn't called. The code is here:
http://phantom.dragonsdawn.net/~gordon/customerportal.module
The browser sends the form data via POST, and the web server responds with "200 OK", sending back the form HTML. It doesn't log any errors. I have no idea how to go about debugging Drupal to determine why the _submit function isn't being called. Can anyone give me some pointers?
Try changing that line: $output .= drupal_render($form['submit']); To: $output .= drupal_render(); in your theme function.
Gordon Messmer wrote:
I'm trying to write a new module, and having some trouble with the forms API. I'm deploying this under Drupal 5. I've been reading the tutorials and documentation for the forms API. A lot of this module is cut and paste from the documentation.
I'm able to generate a form properly, and even theme it. It displays properly in my browser. However, when I submit the form, the _submit function isn't called. The code is here:
http://phantom.dragonsdawn.net/~gordon/customerportal.module
The browser sends the form data via POST, and the web server responds with "200 OK", sending back the form HTML. It doesn't log any errors. I have no idea how to go about debugging Drupal to determine why the _submit function isn't being called. Can anyone give me some pointers?
You don't have a drupal_render($form) at the end which gets all the hidden fields that are necessary, like the form id and form token.
participants (5)
-
Earl Dunovant -
Earl Miles -
Gordon Messmer -
Henrique Recidive -
Steve Ringwood