您的位置:首页 > 其它

Drupal Commerce alter checkout form and custom validate

2016-06-01 15:06 260 查看

Drupal Commerce: How to alter the checkout form and how to add the custom validation

Commerce has its own API http://api.drupalcommerce.org/, that we have used it to adapt the checkout form to our requirements.

Description of the required functionality

In the billing information of an order we have added the fields “Request invoice” and “NIF/CIF” (ID). By default the field “Request invoice” is not checked and “NIF/CIF” is hidden and not required. When the buyer checks the field “Request invoice”
the field “NIF/CIF” becomes visible and required.

Proposed solution

Adding the code that changes the field “NIF/CIF” when the user checks “Request invoice”. By using hook_form_FORM_ID_alter(&$form, &$form_state, $form_id)
Adding a callback to validate the form hook_commerce_checkout_pane_info_alter(&$checkout_panes)
Adding the validation function commerce_billing_pane_validate(&$form, &$form_state, $checkout_pane, $order)
Step 1. Adding the alter form to add the behavior of the field. field_request_invoice

?
Step 2. Alter the customer_profile_billing panel to add the callback to the validation function

?
Step 3. Adding the custom validation function

?
Now, the billing panel in the checkout form shows this



 

We hope this is of help. If you know another way to do this or you have another idea you can write a comment. Thanks!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: