2

Newbie confused between form_validate and hook_validate

http://drupal.org

Hi,
I'm a newbie in Drupal and I'm pretty much confused about the use of hook_validate.

What I want is simple: a user must fill a form to enter parameters that are required to do a particular calculation.
Following example from book "Pro Drupal Development" (joke module), I've created a module with hook_form, hook_validate and hook_insert.

My form contains an element of #type='file' (say, $form['myfile']) and I check the uploaded file has good format (contains exactly 9 columns, etc) in hook_validate:

function mymodule_validate($node) {
//...
$file = file_save_upload('myfile',$validators);
$handle = fopen($file->filepath, "r");
//...check data here
}

When file passes validation, I want to insert (in hook_insert) data from the file to one of my tables. The problem I have is that I don't know how to recover info from $file variable. I thought a good idea would be to pass info from hook_validate to hook_insert via a change to $node but there is an issue about that: http://drupal.org/node/336305

I tried another way. I added a validate and a submit property to my node form:

function mymodule_form($node) {
//...
$form['#validate'][] = 'mymodule_form_validate';
$form['#submit'][] = 'mymodule_form_submit';
}

read more

Read »
Created by Dplanet 2 years 18 weeks ago
Category: Modules   Tags:

PSD to Drupal Theme

Drupal Development

Module Development

Get an Estimate

Tags for Newbie confused between form_validate and hook_validate

Recent comments