To reproduce:
create a simple node type, or use an existing on (page, story should work) Add this code to hook_validate so you can see what's going on:
drupal_set_message("In hook_validate, title is $node->title");
Enter a title, "foo".
Hit Preview
What happens behind the scenes is
1) hook_validate is called without taking into account $POST['edit']. That is, title is null.
2) hook_validate is not called with title= foo. More importantly, no values from the form are validated.
The problem starts with this call to node_preview (in node.module):
if ($op == t('Preview')) {
$form['node_preview'] = array('#value' => node_preview(array2object($_POST['edit'])), '#weight' => -100);
}
While node_preview tries to validate the "node" created from $_POST['edit'], it never does, because the node has no type (it can't determine which module to invoke hook_validate).
One fix might be to change:
$form['type'] = array('#type' => 'value', '#value' => $node->type);
into:
$form['type'] = array('#type' => 'hidden', '#value' => $node->type);
This would set $_POST['edit']['type'] and cause node_preview to actually call hook_validate. If you try this, you'll see hook_validate is called twice. The first call should not occur, IMHO, but that's another issue I guess.
I suspect some others of these should be hidden fields and not just form values, for the same reason:
(see node.module)
/**
* Basic node information.
* These elements are just values so they are not even sent to the client.
*/
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
$form['vid'] = array('#type' => 'value', '#value' => $node->vid);
$form['uid'] = array('#type' => 'value', '#value' => $node->uid);
$form['created'] = array('#type' => 'value', '#value' => $node->created);
$form['changed'] = array('#type' => 'value', '#value' => $node->changed);
$form['type'] = array('#type' => 'hidden', '#value' => $node->type);
Comment | File | Size | Author |
---|---|---|---|
#11 | forms4_0.patch | 11.85 KB | asimmonds |
#10 | forms4.patch | 11.2 KB | chx |
#7 | node_cycle_0.patch | 10.12 KB | chx |
#4 | node_cycle.patch | 10.12 KB | chx |
Comments
Comment #1
chx CreditAttribution: chx commentedOver my dead body change any of those into hidden. I'll create a real fix. Stay tuned.
Comment #2
Dave Cohen CreditAttribution: Dave Cohen commentedPerhaps simply an array_merge with $_POST['edit']? I'm sure there are a number of ways.
Glad you're on it,
-Dave
Comment #3
chx CreditAttribution: chx commentedComment #4
chx CreditAttribution: chx commentedAdrian has added some tree fixes, Steef has added some url() calls.
The major and relevant stuff is that I changed how the node form is built, now it's two pass. This was we actually have the relevant but only the relevant node info.
Will check the concept with poll. Please review.
Comment #5
gtcaz CreditAttribution: gtcaz commentedSite will not load after applying this patch on a PHP5.0.4 install. Trying to dig into the problem now. Not getting any error messages...
Comment #6
moggy CreditAttribution: moggy commentedjust getting blank pages with this patch too.
BTW running PHP 4.3.8
Comment #7
chx CreditAttribution: chx commentedD'oh. How did this version of form.inc got into a patch?? There was a ) missing.
Comment #8
asimmonds CreditAttribution: asimmonds commentedTesting the patch:
Missing ')' line #58 in form.inc
admin/access/permissions save fails, something wrong with the form tree, as there is no longer a checkboxes array
admin/node page errors with: Invalid argument supplied for foreach() in includes\form.inc on line 240
admin/themes save disables all themes
but on top of that, node preview now works...
Comment #9
chx CreditAttribution: chx commentedFinally! Someone who knows what's a review :) Adrian has played with the trees, I was playing with the node stuff. Looking into that.
Comment #10
chx CreditAttribution: chx commentedPlease review. I fixed what asimmonds found. An "it is broken" is not a review. Thanks.
Comment #11
asimmonds CreditAttribution: asimmonds commentedI have updated the patch, correcting a value to #value in node.module and some spacing.
Node preview and submission work.
The problems I found in #8 all test OK now.
Comment #12
chx CreditAttribution: chx commentedhunmonk says that adrian has some cool stuff on Benton and I'll need to check with him. Stay tuned.
Please do not change the status until then.
Comment #13
chx CreditAttribution: chx commentedComment #14
(not verified) CreditAttribution: commented