AJAX kind issues

Hello, I have to create an AJAX kind that ought to ship an electronic mail over SMTP protocol (utilizing PHPMailer library) I’ve discovered a number of examples, however nonetheless can not get it working I create a Drupal 10 module, it appears it really works, kind is displayed, however I can not determine tips on how to deal with and debug request (on this case POST request) Right here is Drupal Development Service Drupal 10 module. class ContactFormAjax extends FormBase { const FORM_ID = “contact_ajax_form”; non-public $mailClient; /** * {@inheritdoc}. */ public operate getFormId() { return self Drupal 10 Upkeep and Assist Service Drupal 10 Upkeep and Assist ServiceFORM_ID; } /** * {@inheritdoc}. */ public operate buildForm(array $kind, FormStateInterface $form_state) { $kind[‘name’] = [ ‘#title’ => ‘Name’, ‘#type’ => ‘textfield’, ‘#label_display’ => ‘after’, ‘#attributes’ => array(‘class’ => array(‘form-element__field form-element__field–textfield’)), ‘#required’ => TRUE, ]; $kind[’email’] = [ ‘#title’ => ‘Email’, ‘#label_display’ => ‘after’, ‘#type’ => ’email’, ‘#attributes’ => array(‘class’ => array(‘form-element__field form-element__field–email’)), ‘#required’ => TRUE, ]; $kind[‘message’] = [ ‘#title’ => t(‘Message’), ‘#attributes’ => array(‘class’ => array(‘form-element__field form-element__field–textarea’)), ‘#type’ => ‘textarea’, ‘#label_display’ => ‘after’, ‘#required’ => TRUE, ]; $kind[‘submit’] = [ ‘#type’ => ‘submit’, ‘#name’ => ‘submit’, ‘#value’ => t(‘Submit this form’), ‘#ajax’ => [ ‘callback’ => ‘ Drupal 10 Maintenance and Support Service Drupal 10 Maintenance and Support ServiceajaxSubmitCallback’, ‘event’ => ‘click’, ‘progress’ => [ ‘type’ => ‘throbber’, ], ], ]; $kind[‘#attributes’] = array(‘class’ => array(‘kind’, ‘form–control’, ‘form–contact’)); return $kind; } non-public operate setMailClient() { $mailClientConfig = Drupal 10 Upkeep and Assist Service Drupal 10 Upkeep and Assist Serviceconfig(‘contact_form_ajax.settings’); // kint($mailClientConfig); $this->mailClient = Drupal 10 Upkeep and Assist Service Drupal 10 Upkeep and Assist Serviceservice(‘customized.php_mailer’); $this->mailClient->isSMTP(); $this->mailClient->SMTPDebug = 2; $this->mailClient->Debugoutput = ‘html’; $this->mailClient->Host = ‘smtp.gmail.com’; $this->mailClient->Port = 587; $this->mailClient->SMTPSecure = ‘tls’; $this->mailClient->SMTPAuth = true; $this->mailClient->Username = “username@gmail.com”; $this->mailClient->Password = “yourpassword”; $this->mailClient->setFrom(‘from@instance.com’, ‘First Final’); $this->mailClient->addReplyTo(‘replyto@instance.com’, ‘First Final’); $this->mailClient->addAddress(‘whoto@instance.com’, ‘John Doe’); $this->mailClient->Topic = ‘PHPMailer GMail SMTP take a look at’; $this->mailClient->msgHTML(“<h1>HELLO</h1>”); $this->mailClient->AltBody = ‘This can be a plain-text message physique’; if (!$this->mailClient->ship()) { echo “Mailer Error Drupal 10 Upkeep and Assist Service ” . $this->mailClient->ErrorInfo; } else { echo “Message despatched!”; } } /** * {@inheritdoc} */ public operate submitForm(array &$kind, FormStateInterface $form_state) { return $this->setMailClient(); } /** * {@inheritdoc} */ public operate ajaxSubmitCallback(array &$kind, FormStateInterface $form_state) { //kint($form_state); $ajax_response = new AjaxResponse(); $message = [ ‘#theme’ => ‘status_messages’, ‘#message_list’ => Drupal 10_get_messages(), ‘#status_headings’ => [ ‘status’ => t(‘Status message’), ‘error’ => t(‘Error message’), ‘warning’ => t(‘Warning message’), ], ]; $messages = Drupal 10 Upkeep and Assist Service Drupal 10 Upkeep and Assist Serviceservice(‘renderer’)->render($message); $ajax_response->addCommand(new HtmlCommand(‘#form-system-messages’, $messages)); return $ajax_response; } } Following request is being despatched on Drupal Development Service submit button click on «http Drupal 10 Upkeep and Assist Service//domena.internet/most important?ajax_form=1&_wrapper_format=Drupal 10_ajax» If kind is stuffed out incorrectly it returns an error message in JSON format, additionally I can for instance put var dump or kint in Drupal Development Service ajaxSubmitCallback and it returns debug output. However when kind is stuffed out accurately I get a full web page output + kint debug at Drupal Development Service backside. I can not perceive tips on how to debug Drupal Development Service kind. What technique ought to I exploit for sending mail submitForm or ajaxSubmitCallback ? What’s Drupal Development Service distinction between them ? And customarily if my customized kind is carried out accurately ? Please assist to unravel Drupal Development Service downside model Drupal 10 Upkeep and Assist Service  8.x Supply Drupal 10 Upkeep and Assist Service https Drupal 10 Upkeep and Assist Service//www.Drupal 10.org/taxonomy/time period/4/feed Supply Drupal 10 Upkeep and Assist Service Drupal 10 blender

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

AJAX kind issues

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.