admin/settings/node has a setting for "Preview post" as optional or required. Setting this to required sets "node_preview" in variable table, but this doesn't seem to be used anywhere. I see both Preview and Submit buttons in create new page or new forum topic in today's cvs.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DriesK’s picture

Assigned: Unassigned » DriesK
Status: Active » Needs review
FileSize
1.4 KB

Making the submit button appear only when 'preview' has been clicked isn't that difficult, it can be done in node_form(), at the place where the submit button array is located now by checking $_POST['op'].

However, we only want the submit button to show when 'preview' has been clicked, _and_ there are no errors in the form. We can't use #post_process, since this is also called before drupal_form_validate() (so renaming it to #after_build as has been suggested would be great). Therefore, the only way I could think of is to use #theme, since theming is the only thing that still happens after form validation. Patch attached for review.

DriesK’s picture

Status: Needs review » Needs work

something's wrong. submit is not recognized. I'll try to figure it out.

DriesK’s picture

Status: Needs work » Needs review
FileSize
1.25 KB

I took a look at this one again, and it wasn't simple. I tried several possible solutions, and this one is the only one that works as what one expects from a preview button (only show the submit button after preview, and only if there are no errors in the form).

I integrated the solution with node_form_add_preview() to minimize the number of calls to node_validate() and _form_validate().

DriesK’s picture

FileSize
1.25 KB

This one is better.

Dries’s picture

Not sure about this patch. Calling internal form API functions (_form_validate) isn't a good idea, IMO.

DriesK’s picture

FileSize
1.21 KB

changed it to drupal_validate_form (which calls _form_validate). I also did some further cleanup of the code, and removed the node_validate call, which is called by _form_validate (I missed that in the previous patch).

chx’s picture

Status: Needs review » Reviewed & tested by the community

Let's answer the question: why do you need to call drupal_validate_form? Because you want to include preview only if the form validates. Is there another way to do this? No. As we can see in drupal_get_form , after drupal_validate_form is called (and there is no submit) the next step is theming. We do not want theming to insert the preview. Validate validates and does not change anything. Q.E.D.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Last patch looks good. Great work. Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)