Я знаю, что этот вопрос задавался неоднократно, но ни одно из решений, которые я нашел, не работает для меня. У меня есть простой плагин wordpress, который выводит форму html через шорткод на странице. Когда я заполняю форму, она не вызывает обратный вызов действия формы, и я не могу понять, почему. Вот мой код:
<?php
/*
Plugin Name: Form Submit Test
Plugin URI: http://10.0.2.15/wp-content/plugins/form-submit-test
Description: Testing to get these forms to submit
Version: 1.0.0
Author: Randy Young
Author URI: http://example.com
License: GPLv2 or later
*/
// security check
defined('ABSPATH') or die('Illegal Access');
define( 'FormSubmitTest_VERSION', '1.0.0' );
class FormSubmitTest
{
function fst_shortcode() {
return $this->html_form_code();
}
private function html_form_code() {
error_log('html_form_code()');
$html = '';
$html .= '<form action="' . esc_url( admin_url('admin-post.php')) . '" method="post">'; //
$html .= '<input type="hidden" name="action" value="fst_action_hook"';
$html .= '<p>';
$html .= 'Your Name (required) <br />';
$html .= '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="40" />';
$html .= '</p>';
$html .= '<p>';
$html .= 'Your Email (required) <br />';
$html .= '<input type="email" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" />';
$html .= '</p>';
$html .= '<p>';
$html .= 'Subject (required) <br />';
$html .= '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value="' . ( isset( $_POST["cf-subject"] ) ? esc_attr( $_POST["cf-subject"] ) : '' ) . '" size="40" />';
$html .= '</p>';
$html .= '<p>';
$html .= 'Your Message (required) <br />';
$html .= '<textarea rows="10" cols="35" name="cf-message">' . ( isset( $_POST["cf-message"] ) ? esc_attr( $_POST["cf-message"] ) : '' ) . '</textarea>';
$html .= '</p>';
$html .= '<p><input type="submit" name="cf-submitted" value="Send"/></p>';
$html .= '</form>';
return $html;
}
}
// instantiate the FormSubmitTest class
if( class_exists('FormSubmitTest')) {
$formSubmitTest = new FormSubmitTest();
}
add_action( 'wp_post_nopriv_fst_action_hook', 'fst_action_function' ); // need this to serve non logged in users
add_action( 'wp_post_fst_action_hook', 'fst_action_function' );
// THE FUNCTION
function fst_action_function() {
error_log('fst_action_function()');
wp_redirect(admin_url('admin.php?page=10.0.2.15/index.php/ringwood2/'));
exit;
}
// create a shortcode to add to the page
add_shortcode('form_submit_test', array( $formSubmitTest, 'fst_shortcode'));
?>
Я вижу error_log('html_form_code()'); результат в debug.log, но я не вижу error_log('fst_action_function()'); результат обратного вызова. Я также оказываюсь на странице wp-admin/admin-post.php.
Любая помощь будет глубоко оценена.