I'm working on a payment gateway, so I've created a BasePaymentOffsiteForm form where I'm trying to make an ajax callback, but it is not working. Can you help me to know what is wrong with my code?
$form = parent::buildConfigurationForm($form, $form_state);
$form['content'] = [
'#type' => 'container',
'#prefix' => '<div id="validate-phone-number">',
'#suffix' => '</div>',
];
$form['content']['mobile_phone'] = [
'#type' => 'textfield',
'#title' => $this->t('Mobile phone'),
];
$form['content']['validate_client'] = [
'#type' => 'button',
'#value' => $this->t('Validate Client'),
'#ajax' => [
'#callback' => [get_class($this), 'clientValidateForm'],
'event' => 'click',
'wrapper' => 'validate-phone-number',
],
];
$form['content']['cancel'] = [
'#type' => 'link',
'#title' => $this->t('Cancel'),
'#url' => Url::fromUri($form['#cancel_url']),
];
return $form;
}
public static function clientValidateForm(array $form, FormStateInterface $form_state) {
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Pay',
];
return $form['submit'];
}
It never gets in cientValidateForm method.