开发者

How to validate the input of views exposed form in drupal-6

开发者 https://www.devze.com 2023-02-28 17:07 出处:网络
I used views exposed form to filter data, is it possible for me to add a v开发者_如何转开发alidation function to validate the input before it is handled by the viewsYes,

I used views exposed form to filter data, is it possible for me to add a v开发者_如何转开发alidation function to validate the input before it is handled by the views


Yes,

With a small custom module you can implement hook_form_alter().

I usually start with this:

<?php

function your_module_form_alter(&$form, &$form_state, $form_id){
 drupal_set_message($form_id);
}

?>

once you get your views exposed filter form id, you operate inside of an "if"... so you don't alter all of your forms

<?php

function your_module_form_alter(&$form, &$form_state, $form_id){
  if($form_id=="your_form_id"){
    //add to the validation callback array( don't override it! )
    $form['#validate'][] = '_your_custom_validation';
  }
}

function _your_custom_validation($form, &$form_state){
  //validate stuff, using form_set_error()
}

?>

an example validation function: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#validate

0

精彩评论

暂无评论...
验证码 换一张
取 消