简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM