Currently, confirm_form() says it outputs a confirmation form/returns a complete form for confirming an action.

This snagged me b/c I couldn't figure out why my modules suddenly broke that used a syntax like...

  $output = drupal_get_form('confirm_form', ...);

This breaks b/c FAPI now passes in $form_state as the first argument to any form builder function, but confirm_form() doesn't accommodate this. Instead, you see all over in core that confirm_form() is used to build a form array from within a form builder function much like system_settings_form().

For system_settings_form(), the documentation reads "Add default buttons to a form and set its prefix."

Perhaps confirm_form() should follow suit with the "add" language instead of sounding like a valid form builder function itself. I'd also recommend dropping the first line of "Output a confirmation form" altogether as the function doesn't really do that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Barry Madore’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Documentation in CVS » documentation

Moving

betz’s picture

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443

jhodgdon’s picture

Category: feature » bug

It does indeed look like the doc for confirm_form() still needs updates as stated above...
http://api.drupal.org/api/function/confirm_form/7

mr.baileys’s picture

Status: Active » Needs review
FileSize
2.98 KB

Here's an attempt at improving the doxygen comments for confirm_form():

  • Technically, confirm_form is not a form builder function as defined in http://drupal.org/node/1354#forms, so I removed the "@ingroup forms" directive
  • The current doxygen comment has the following text:

    If the submit handler for this form is invoked, the user successfully confirmed the action. You should never directly inspect $_POST to see if an action was confirmed.

    This is confusing at best, since confirm_form() does not have a submit handler. The submit handler belongs to the form builder function that invokes confirm_form(). Slightly reworded.

  • When using an array for the $path parameter, only the 'path' key/value are required, the others are optional, added this to the docs.
  • $path is ignored if a 'destination' query parameter is present in the URL, added this to the docs.
jhodgdon’s picture

Status: Needs review » Needs work

Looks fairly good, and it's definitely an improvement! A few things I think should be fixed:

a) $path - this can contain much more than just 'path', 'query', and 'fragment' components. It can have anything relevant for $options in http://api.drupal.org/api/function/l/7

b) Punctuation/style (not from your patch, but in this function):
Additional elements to inject into the form, for example hidden elements.
==>
Additional elements to add to the form; for example, hidden elements.

c) You might mention that the default for $yes is t('Submit') and for $no is t('Cancel'). Also, in other defaults, technically they are wrapped in t().

d) Grammar/usage:
A caption for the link which cancels ...
==>
A caption for the link that cancels ...

e) I guess from this documentation it is still not clear to me how you would define the submit handler, which might be a good idea to document, since it's mentioned in the doc?

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.3 KB

Thanks!

I've changed the wording for the $path parameter to explain that a $path array is passed as the $options parameter to l(). Also converted the "string or array" to a list.

You might mention that the default for $yes is t('Submit') and for $no is t('Cancel'). Also, in other defaults, technically they are wrapped in t().

I've added the defaults for $yes and $no, and wrapped the default for $description in t(). I left the examples for $yes and $no alone (not wrapped in t(), as these feel like (for lack of a better word) non-technical examples

I guess from this documentation it is still not clear to me how you would define the submit handler

I agree that this isn't particularly clear. What about:

If the submit handler for a form that implements confirm_form() is invoked...

?

jhodgdon’s picture

Status: Needs review » Needs work

Great! I am very happy now with the text that you wrote for this function. There are still a couple of minor items to improve:

a) Punctuation:
- Additional elements to add to the form; for example hidden elements.
You need a comma after "for example,"

b) List formatting:

+ *   The page to go to if the user cancels the action. This can be either
+ *   - a string containing a drupal path;
+ *   - an associative array with a 'path' key. Additional array values are
+ *     passed as the $options parameter to l().

Please check out our guidelines for formatting lists on http://drupal.org/node/1354 (near the top). Precede with :, each item starts with capital letter, ends with period. Also Drupal should be capitalized.

c) The $no parameter still doesn't say what its default is.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.33 KB

Thanks, fixed the remaining issues...

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Great work!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

jhodgdon’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

We should probably fix this in Drupal 6 as well. The documentation there is even worse.

mr.baileys’s picture

FileSize
3.35 KB

Here is a straight re-roll for D6. The function itself hasn't changed between versions, but I'm not aware of differences between D6 and D7 doxygen guidelines so it might require some tweaking.

mr.baileys’s picture

Status: Patch (to be ported) » Needs review
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Thanks!

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed to Drupal 6.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.