Skip to content

Commit

Permalink
adding check for variable before looping on it. changing reference pa…
Browse files Browse the repository at this point in the history
…ram ( due to change in webform api ). do not pass empty zip code upon submission.
  • Loading branch information
troynt committed Feb 25, 2011
1 parent e27667e commit 39afb6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ function _webform_display_vs_webform($component, $value, $format = 'html') {
* through the returned array, validating the emails;
* If the email is valid webform will send an email.
*/
function _webform_submit_vs_webform($component, &$value) {
function _webform_submit_vs_webform($component, $value) {
if ( empty($value) || !is_array($value['vs_webform']['candidates']) ) return NULL;

$ret = array(0 => ''); //placeholder for serialized value
Expand Down Expand Up @@ -607,18 +607,25 @@ function _vs_webform_validate($form, &$form_state, $allow_no_candidates_selected
return; // wait until we have a valid zip or state
}

$allowed_candidates = vs_webform_get_candidates(array(
'state' => $vs_webform['state']['#value'],
'zip' => $vs_webform['zip']['#value']
));
if( empty($vs_webform['zip']['#value']) ) {
$allowed_candidates = vs_webform_get_candidates(array(
'state' => $vs_webform['state']['#value']
));
}
else {
$allowed_candidates = vs_webform_get_candidates(array(
'state' => $vs_webform['state']['#value'],
'zip' => $vs_webform['zip']['#value']
));
}

if ( empty($allowed_candidates) ) {
form_set_error('vs_webform',t('Unable to find officials with information provided.'));
return;
}

$candidates = element_children($vs_webform['candidates']);//alias
if( !$allow_no_candidates_selected ) {
if ( !$allow_no_candidates_selected ) {
if ( empty($vs_webform['candidates']) ) {
form_set_error('vs_webform', t('Please select one or more officials.'));
return;
Expand Down
11 changes: 9 additions & 2 deletions drupal/sites/all/modules/contrib/vs_webform/vs_webform.module
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ function vs_webform_get_candidate($candidateId, $partial_candidate_xml = NULL, $
return $candidates[$candidateId];
}

/**
* Provides an array of candidates keyed on candidate id
* @param $args an array with state and zip
* @return unknown_type
*/
function vs_webform_get_candidates($args) {
$args['zip'] = preg_replace('@[^\d]@', '', $args['zip']);//strip non digits

Expand Down Expand Up @@ -513,8 +518,10 @@ function vs_webform_get_office_types() {
if (!$types || empty($types->data)) {
$types = array();
$result = _vs_webform_api('Office.getTypes', array(), NULL, 'json');
foreach ($result->officeTypes->type as $type) {
$types[$type->officeTypeId] = $type->name;
if ( isset($result) && is_array($result->officeTypes->type) ) {
foreach ($result->officeTypes->type as $type) {
$types[$type->officeTypeId] = $type->name;
}
}
cache_set('vs_webform_office_types', $types);
return $types;
Expand Down

0 comments on commit 39afb6b

Please sign in to comment.