Confused on AJAX submit form through page template

<form action=”<?php echo get_template_directory_uri() . “/validation.php”; ?>” id=”contactForm”> 😱 So I’ll outline the basic fundamentals, so you have a framework to move forwards with Fixing Admin AJAX So I’ll cover this very briefly as it’s not the crux of my answer, but would be useful: Add a hidden input field named action rather than adding … Read more

fetching via fetch/ajax gutenberg block data from third party

Well, I figured it out. Though my solution is probably far from elegant (I’m not making concessions for timeouts or usability/accessibility). My problem was mostly overzealous configuration, copy and paste errors, and needing to apply async/await keywords. Attributes look like this: attributes: { url: { source: ‘attribute’, type: ‘string’, selector: ‘.o_microlink’, attribute: ‘href’, }, title: … Read more

wp_ajax action is not running

Where are you calling add_action()? If it’s in a place where you’re already outputting HTML, it’s too late, and that’s probably a place that wont even be looked at during an AJAX request. You should include that code in your theme’s functions.php file, or as early as possible in a plugin.

Is there a way to optimize function that is used for returning data in an ajax-call?

Since you are not using $field_value after if-else, you can start rewriting that if if (substr($field_value, 0,4) === ‘http’) { $field_value=”<a target=”_blank” href=”” . $field_value . ‘”>’ . $field_value . ‘</a>’; } /* else { no else statement here! } */ and just use it later like this: $html .= ‘<span class=”lajax-value”>’ . $field_value . … Read more