Commit c1548c48 authored by jenlampton's avatar jenlampton

Add a validate handler that checks the value in the amount field. Reject form submission if zero.

parent f558443d
......@@ -174,11 +174,43 @@ function authorizenetwebform_form_webform_client_form_alter(&$form, &$form_state
'type' => 'setting'
);
// Submit handler. Adding it here the *second* submit handler.
// Add validation handler.
$form['#validate'][] = 'authorizenetwebform_webform_client_form_validate';
// Add submit handler. Adding it here the *second* submit handler.
$first = array_shift($form['#submit']);
array_unshift($form['#submit'], $first, 'authorizenetwebform_webform_client_form_submit');
}
/**
* Webform validate handler.
*
* @see authorizenetwebform_form_webform_client_form_alter().
*/
function authorizenetwebform_webform_client_form_validate($form, &$form_state) {
// Get key mappings for this webform.
$nid = $form_state['values']['details']['nid']; // Nice shorthand.
$variable_name = 'authorizenetwebform_key_map_' . $nid;
// Get the mapping of webform field => AuthNet field key.
$field_map = variable_get($variable_name, array());
// Get the mapping of AuthNet field key => webform field.
$flipped_map = array_flip($field_map);
// Get the amount.
$field_values = _authorizenetwebform_flatten_form_values($form_state['values']['submitted']);
$amount_key = $flipped_map['x_amount'];
$amount = $field_values[$amount_key];
// Do not allow submission with zero dollar amount.
if (empty($ammount)) {
$string = t('The amount must be greater than 0.');
drupal_set_message($string, 'error');
// Stop the submission.
$form_state['rebuild'] = TRUE;
}
}
/**
* Webform submit handler.
*
......@@ -400,9 +432,12 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
if ($response_array['messages']['resultCode'] == 'Ok') {
// Extrat the response info we need for our records.
$response_info = $response_array['transactionResponse'];
$text = '';
$failure = FALSE;
// Extrat the response info we need for our records.
if (array_key_exists('transactionResponse', $response_array)) {
$response_info = $response_array['transactionResponse'];
}
// Decliend || Error.
if ($response_info['responseCode'] == 2 || $response_info['responseCode'] == 3) {
......@@ -486,9 +521,9 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
// @todo: Save this data into a more permanent location than watchdog?
// Also print response to screen.
if (module_exists('devel')) {
dpm($response_array);
}
//if (module_exists('devel')) {
//dpm($response_array);
//}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment