You are here

function webform_validation_rule_save in Webform Validation 6

Same name and namespace in other branches
  1. 7 webform_validation.module \webform_validation_rule_save()

Save a validation rule. Data comes from the admin form or nodeapi function in case of node clone

2 calls to webform_validation_rule_save()
webform_validation_manage_rule_submit in ./webform_validation.admin.inc
Submit handler to add / edit a rule
webform_validation_node_clone in ./webform_validation.module
Adds support for node_clone module

File

./webform_validation.module, line 371

Code

function webform_validation_rule_save($values) {

  // save rules data
  if ($values['action'] == 'add') {
    drupal_write_record('webform_validation_rule', $values);
    $ruleid = $values['ruleid'];
    if ($ruleid && array_filter($values['rule_components'])) {
      webform_validation_save_rule_components($ruleid, array_filter($values['rule_components']));
      module_invoke_all('webform_validation', 'rule', 'add', $values);
    }
  }
  if ($values['action'] == 'edit') {
    drupal_write_record('webform_validation_rule', $values, 'ruleid');
    $ruleid = $values['ruleid'];

    // delete earlier component records for this rule id
    db_query("DELETE FROM {webform_validation_rule_components} WHERE ruleid = %d", $ruleid);
    if ($components = array_filter($values['rule_components'])) {
      webform_validation_save_rule_components($ruleid, $components);
      module_invoke_all('webform_validation', 'rule', 'edit', $values);
    }
  }
}