在drupal8里创建一个表单处理程序

1、文件结构:
▾ modules/
▾ custom/

▾ my_custom_form_handler/
  ▾ src/
    ▾ Plugin/
      ▾ WebformHandler/
      
      

2、然后,您应该在WebformHandler目录中创建处理程序文件。我们将其称为ExampleFormHandler.php,文件应遵循以下模板:

<?php
namespace Drupal\my_custom_form_handler\Plugin\WebformHandler;
 
use Drupal\Core\Session\Account\Interface;
use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;
 
use Guzzle\Http\Client;
use Guzzle\Http\Exception\RequestException;
 
/**
 * Form submission handler.
 *
 * @WebformHandler(
 *   id = "example_form_handler",
 *   label = @Translation("Example form handler"),
 *   category = @Translation("Examples"),
 *   description = @Translation("An example form handler"),
 *   cardinality = Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
 */
class ExampleFormHandler extends WebformHandlerBase {
 
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    // Your code here.
  }
}
标签:

相关文章

1 条评论

  1. 北京艺术培训

    感谢分享 赞一个

发表评论