I create an Ubercart settings form for the PayJunction processing gateway.
The form includes a login & password, which works great now, but I needed to set the password to a default on validation if the user did not change the password content (otherwise it gets erased!)
function _mo_payjunction_settings_form() {
// add login/password items
...
// password requires a validation
$form['#validate'][] = 'mo_payjunction_validate';
...
return $form;
}
This does not work because you "improperly" merge the array as shown here:
...
if (function_exists($gateway['settings'])) {
$gateway_settings = $gateway['settings']();
if (is_array($gateway_settings)) {
$form['gateways'][$gateway['id']] = array_merge($form['gateways'][$gateway['id']], $gateway_settings);
}
}
...
Of course, using array_merge() is real fast, but it should never be that large an array and it is only for admins. So I think we could have yet another foreach() that checks the $gateway_settings and for any #<name> we put that at the top of the destination array. That way #validate and #submit (at least) would work.
This is very minor since there is an okay work around which is to have a hook_form_alter() which can check for the uc_payment_gateways_form and adds the necessary validation function(s), but that's a bit ugly.
Thank you.
Alexis Wilke
Comments
Comment #1
Island Usurper commentedMaybe we should specify that the array will be merged in the documentation. Can you use #element_validate in your module's function instead?
Comment #2
longwave#element_validate should be usable here. As nobody else has posted in this issue I suspect we do not need to change this otherwise.
Comment #3
AlexisWilke commentedlongwave,
Well... I never tried the #element_validate. It might work. At this time, I use my work around which is to have the #validate added in the ..._form_alter() hook.
Thank you.
Alexis