Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
A
authorizenetwebform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
authorizenetwebform
Commits
c1548c48
Commit
c1548c48
authored
Jan 04, 2019
by
jenlampton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a validate handler that checks the value in the amount field. Reject form submission if zero.
parent
f558443d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
6 deletions
+41
-6
authorizenetwebform.module
authorizenetwebform.module
+41
-6
No files found.
authorizenetwebform.module
View file @
c1548c48
...
...
@@ -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);
//
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment