Как сделать пользовательскую форму в посте WordPress с помощью стороннего плагина?

У меня есть детская тема, где я сделал пользовательскую форму. Он имеет те же поля, что и форма в плагине, который я использую (используя Anspress). Я хочу, чтобы пользователи могли отправлять через мою форму. Я попытался использовать метод POST, чтобы получить форму для публикации в файле PHP, где находится форма вопроса плагина. Однако, когда я нажимаю кнопку отправки, ничего не происходит.

Я бы согласился на какую-то подсказку, чтобы начать меня. Я следовал руководству W3Schools и также нашел здесь аналогичный вопрос, который соответствует тому, что я пытался сделать ниже.

Форма детской темы

<?php /* Template Name: Main Form */ ?>



<?php get_header(); ?>


<div class="container">
<div class="row">
<form action=".../.../.../plugins/anspress-question-answer/includes/ask-form.php" method="POST">
<div class="col-md-6">

<div class="form-group">
<input id="addtitle" type="text" name="title" class="form-control" placeholder="Title">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" name="description" id="addquestion" placeholder="Find this for me..."></textarea>
</div>
<div class="form-group">
<div class="input-group" id="addtags">
<input type="text" class="form-control" placeholder="Tags">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12" id="main_submit_div" name="submit_button">
<button type="button" class="btn btn-success" id="main_submit_button">Submit</button>
</div>
</div>
</form>
</div>
</div>

Форма плагина в соответствующем PHP-файле

<?php
/**
* Form and controls of ask form
*
* @link http://anspress.io
* @since 2.0.1
* @license GPL2+
* @package AnsPress
*/

class AnsPress_Ask_Form
{
public function __construct()
{
add_filter('ap_ask_form_fields', array($this, 'ask_form_name_field'));
}

public function ask_form_name_field($args){
if(!is_user_logged_in() && ap_opt('allow_anonymous'))
$args['fields'][] = array(
'name' => 'name',
'label' => __('Name', 'ap'),
'type'  => 'text',
'placeholder'  => __('Enter your name to display', 'ap'),
'value' => sanitize_text_field(@$_POST['name'] ),
'order' => 12
);

return $args;
}
}

new AnsPress_Ask_Form;

/**
* Generate ask form
* @param  boolean $editing
* @return void
*/
function ap_ask_form($editing = false){
global $editing_post;

$is_private = false;
if($editing){
$is_private = $editing_post->post_status == 'private_post' ? true : false;
}

$args = array(
'name'              => 'ask_form',
'is_ajaxified'      => true,
'submit_button'     => ($editing ? __('Update question', 'ap') : __('Post question', 'ap')),
'fields'            => array(
array(
'name' => 'title',
'label' => __('Title', 'ap'),
'type'  => 'text',
'placeholder'  => __('Question in one sentence', 'ap'),
'desc'  => __('Write a meaningful title for the question.', 'ap'),
'value' => ( $editing ? $editing_post->post_title : sanitize_text_field( @$_POST['title'] ) ),
'order' => 5,
'attr' => 'data-action="suggest_similar_questions"',
'autocomplete' => false,
),
array(
'name' => 'title',
'type'  => 'custom',
'order' => 5,
'html' => '<div id="similar_suggestions"></div>'
),
array(
'name' => 'description',
'label' => __('Description', 'ap'),
'type'  => 'editor',
'desc'  => __('Write description for the question.', 'ap'),
'value' => ( $editing ? apply_filters('the_content', $editing_post->post_content) : @$_POST['description']  ),
'settings' => apply_filters( 'ap_ask_form_editor_settings', array(
'textarea_rows'     => 8,
'tinymce'           => ap_opt('question_text_editor') ? false : true,
'quicktags'         => ap_opt('question_text_editor') ? true : false ,
'media_buttons'     =>false,
)),
),
array(
'name'  => 'ap_upload',
'type'  => 'custom',
'html' => ap_post_upload_form(),
'order' => 10
),
array(
'name' => 'parent_id',
'type'  => 'hidden',
'value' => ( $editing ? $editing_post->post_parent : get_query_var('parent')  ),
'order' => 20
)
),
);

if(ap_opt('allow_private_posts'))
$args['fields'][] = array(
'name' => 'is_private',
'type'  => 'checkbox',
'desc'  => __('Only visible to admin and moderator.', 'ap'),
'value' => $is_private,
'order' => 12,
'show_desc_tip' => false
);

if(ap_opt('recaptcha_site_key') == '')
$reCaptcha_html = '<div class="ap-notice red">'.__('reCaptach keys missing, please add keys', 'ap').'</div>';
else
$reCaptcha_html = '<div class="g-recaptcha" id="recaptcha" data-sitekey="'.ap_opt('recaptcha_site_key').'"></div><script type="text/javascript"src="https://www.google.com/recaptcha/api.js?hl='.get_locale().'&onload=onloadCallback&render=explicit"  async defer></script><script type="text/javascript">var onloadCallback = function() {
widgetId1 = grecaptcha.render("recaptcha", {
"sitekey" : "'.ap_opt('recaptcha_site_key').'"});
};</script>';

if(ap_opt('enable_recaptcha'))
$args['fields'][] = array(
'name' => 'captcha',
'type'  => 'custom',
'order' => 100,
'html' => $reCaptcha_html
);

/**
* FILTER: ap_ask_form_fields
* Filter for modifying $args
* @var array
* @since  2.0
*/
$args = apply_filters( 'ap_ask_form_fields', $args, $editing );

if($editing){
$args['fields'][] = array(
'name'  => 'edit_post_id',
'type'  => 'hidden',
'value' => $editing_post->ID,
'order' => 20
);
}

$form = new AnsPress_Form($args);

echo $form->get_form();
echo ap_post_upload_hidden_form();
}

/**
* Generate edit question form, this is a wrapper of ap_ask_form()
* @return void
* @since 2.0.1
*/
function ap_edit_question_form()
{
ap_ask_form(true);
}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector