Download & Extend

How Does One (Visibly) Modify Form Values?

Project:Drupal core
Version:4.7.2
Component:forms system
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Specifically I am interested in filtering form values in a contrib module (Superteaser), but I think this post applies to any modification of node form values that should be made apparent to the user on Preview. This issue is preventing me from upgrading the Superteaser module to 4.7 (it works fine in 4.6). Here's what I've tried, in roughly descending order of sensibility:

1) Modifying $node in hook_nodeapi() with $op == 'validate'

The problem with the 'validate' op is that it is incapable of modifying the $node. Looking at node.module, the hook is called from the function node_validate() which does not take $node as a reference, so any changes made in the 'validate' portion of hook_nodeapi() won't stick.

2) Modifying $node in hook_nodeapi() with $op == 'prepare'

The problem with the 'prepare' op is that it's called from node_form_array(). I thought this would be fine since the form appears to be built in this function, but it's only the beginnings of the form, the built-in fields, and so the $node object here contains only a few values: uid, name, type, created, date, and comment. So the stuff I want to filter isn't available in the 'prepare' op.

3) Calling form_set_value() from hook_validate() with $op == 'validate'

The problem here is that the post-processing form values (ie, the ones that go into the DB) are changed, but the values displayed to the user in the form are not changed. This is fine if nobody ever clicks Preview, but not good if they click Preview, see their data unchanged, then click Submit and it *is* changed. In the Superteaser module (and really, any auto-teaser situation) this is definitely no good since an author should be able to leave the teaser field blank, click Preview to have a teaser automatically generated, then fine-tune it by hand.

Anyone have any better ideas?

Comments

#1

Status:active» closed (fixed)

Closing support requests older than 1 month.

#2

I think this is a very valid request. How should one handle this situationo in 4.7? Superteaser is effectively unusable because of this.

nobody click here