Submit Value Not Captured

Created on 17 June 2024, 3 months ago
Updated 18 June 2024, 3 months ago

Describe your bug or feature request.

I'm creating a custom module PocketPay. The basic part is to capture a value from user input. But I have tried for one week, just unable to capture the form value. Very frustrating. So I'm asking for any advice.

The below are the code of file PocketPayPane.php under custom/pocketpay/src/Plugin/Commerce/CheckoutPane and pocketpay.module under pocketpay directory. The form is set on Order_infomation page. When the checkbox is checked, nothing recorded in log. I tried use a text box to see whether that value can be captured. Also no.:

PocketPayPane.php

<?php

namespace Drupal\pocketpay\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Provides a custom checkout pane for PocketPay.
*
* @CommerceCheckoutPane(
* id = "pocketpay_pane",
* label = @Translation("PocketPay Pane"),
* default_step = "order_information",
* )
*/
class PocketPayPane extends CheckoutPaneBase {

/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form['field_pocket_pay'] = [
'#type' => 'checkbox',
'#title' => $this->t('Pocket Pay'),
'#default_value' => $form_state->getValue('field_pocket_pay'),
];

return $pane_form;
}

/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
// Log the checkbox value.
\Drupal::logger('pocketpay')->notice('Checkbox value: @value', ['@value' => $form_state->getValue('field_pocket_pay')]);

// Save the custom boolean field value to the order.
$this->order->set('field_pocket_pay', $form_state->getValue('field_pocket_pay'));
$this->order->save();
}

}

pocketpay.module:

<?php

use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_commerce_checkout_pane_info().
*/
function pocketpay_commerce_checkout_pane_info() {
$panes = [];
$panes['pocketpay_pane'] = [
'title' => t('PocketPay Pane'),
'page' => 'order_information',
'weight' => 0,
'status' => TRUE,
'region' => 'content',
'display_label' => 'above',
];
return $panes;
}

Thank you in advance for any help you can provide!

💬 Support request
Status

Closed: won't fix

Version

2.39

Component

Developer experience

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sdsc
  • Status changed to Closed: won't fix 3 months ago
  • 🇮🇱Israel jsacksick

    The hook_commerce_checkout_pane_info() was necessary in Commerce 1.x (the D7 version), not in Commerce 2. The order shouldn't be saved from submitPaneForm() as this is done by the checkout flow plugin already.
    Just FYI, submitPaneForm() is invoked when the global form is submitted, not right when the checkbox is checked.

    With the abundance of support available in Drupal Answers, the Drupal focused Stack Exchange site, we are no longer answering support requests in the issue queue.

    Support requests opened here will be closed (won't fix), so please search for existing answers or post new questions at:

    https://drupal.stackexchange.com (using the drupal-commerce tag)

Production build 0.71.5 2024