I'm using a computed field to display a form on a node view only to registered users. The form is in a custom module i've written. I simply do a check for user_logged_in and if TRUE then I call drupal_get_form() to display the form.
The form displays properly but the validate and submit functions are not called. However if I submit the modules form (admin/build/modules) then the form will behave as expected once. If I navigate back to the node with the form computed field it will neither validate nor submit until I resubmit the modules form.
Very strange.
Even stranger, if I include a text area field and paste in the same code (with minor alterations to just print the form), then the computed field always behaves as expected.
Finally, if I configure the field to be stored in the database, then the form renders twice in the node view.
Here is my code included in the computed field:
// get the license string
include('./' . drupal_get_path('module', 'saybit_com_downloads') . '/includes/'.$node->field_license_file[0]['value']);
// add HTML to indicate need to agree to the license to download
$node_field[0]['value'] .= '<h2>License Agreement</h2><p>In order to download, please read the following license agreement and agree by checking the checkbox. Then click the download button.</p>';
if (user_is_logged_in())
{
$node_field[0]['value'] .= drupal_get_form('saybit_com_downloads_download_form_with_license', file_directory_path().'/private/'.$node->field_download_file[0]['value'], $license);
}
else
{
$node_field[0]['value'] = '<p>You must have be logged-in to download this file.</p><div><a
href="/login" target="_blank">log-in</a></div><div><a href="/register"
target="_blank">register</a></div>';
}
Any insight would be greatly appreciated.
Thanks!
Ted
Comments
Comment #1
tbenice commentedmore info:
If I copy over the code from the computed field into a text area with php filter, then the form works fine. Also, I can't seem to find any difference in the markup between the 2 methods.
Comment #2
Moonshine commentedI can't say I completely understand your describing, but it seems what you are up against here is combination of node field values being cached in the database and Drupal FAPI validation tokens that are used to prevent tampering. Really what you are trying to accomplish would be better served by using Drupal's hook_nodeapi() call:
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...
You would just trigger your form to build and display according to conditions you set in the "view" $op for hook_nodeapi. Then there is no CCK caching involved and the form is built fresh on the fly.
Comment #3
tbenice commentedThat's true. Guess I was trying to use cck exclusively to do this when what I really need is to write a module for it. Thanks for the tip!