How to avoid writing to database in form submit? I have a webform and I need to validate a condition before you type in the database.

Use the hook_form_alter, this is my code:

function validate_entry_form_alter(&amp;$form, $form_state, $form_id){
  if($form_id == 'webform_client_form_1'){
    $form['#submit'][] = "_validate_entry_webform_client_form_submit_handler";
  }
}

/* function HOOK_FORM_SUBMIT */

function _validate_entry_webform_client_form_submit_handler($form, &amp;$form_state){
  $option = $form['submitted']['eventos']['#value'];
  $data_total = db_query("SELECT count(data) FROM webform_submitted_data WHERE data = $option")-&gt;fetchField();

  print_r('&lt;pre&gt;');
  print_r($data_total);
  print_r('&lt;/pre&gt;');
  exit();
}


I've noticed that my function to handle the submit is handled when it wrote in database.

I need a "hook" where you can get all the results before they are written to database. Validate the data and if everything is correct, follow the workflow in database insert.
Form validation is called in the the first part af your code not in the submit function. Add another parameter to your form_alter: 

$form['#validate'][] = 'nameOfMyModule_functionName_validate'; 
$form['#submit'][] = "_validate_entry_webform_client_form_submit_handler";


When validation passes, the submit function will be called. if not form_set_error can be called displaying a message like so:

function nameOfMyModule_functionName_validate($form, &amp;$form_state) {
// Check for the color 'blue'.
    if ($form_state['values']['color'] == 'blue') {
    form_set_error('color', 'Sorry, your favorite color is actually yellow.');
    }
}