Felix Eve
Felix Eve

Reputation: 3864

How to validate hook block configure form in Drupal 7

In Drupal 7 hook_block_configure and hook_block_save provide a method to modify a blocks settings and save these values.

But how would I carry out validation on the form before saving the values?

Upvotes: 0

Views: 1916

Answers (2)

Antti Alamäki
Antti Alamäki

Reputation: 1

If you wish to add validation for the whole form, this is not really possible. The best way I have managed to implement myself is to add a custom function to the code with $edit as a parameter with Boolean as a return value. Then call the function in the hook_block_save() before saving data in order to perform the extra checks. Works fine with the only exception that it will not highlight in red values that are incorrect in the form.

Upvotes: 0

lgomezma
lgomezma

Reputation: 1637

As found here when configuring your form element you should add an '#element_validate' that points to a custom validation function of the element. You can find more information in the Form Api here

Upvotes: 4

Related Questions