Php 为什么我的表格是';s提交按钮不工作?
我正在修改一个WP插件(PHP;WP的最新版本)。它有一个用户可以提问的表单。它有自己的提交按钮。我发现了一个操作钩子,我可以将自己的代码添加到表单中,因此我添加了Braintree最简单的支付表单-DropIn UI 问题:Php 为什么我的表格是';s提交按钮不工作?,php,wordpress,forms,Php,Wordpress,Forms,我正在修改一个WP插件(PHP;WP的最新版本)。它有一个用户可以提问的表单。它有自己的提交按钮。我发现了一个操作钩子,我可以将自己的代码添加到表单中,因此我添加了Braintree最简单的支付表单-DropIn UI 问题: class FD_Braintree_Form { public function fd_bt_form() { echo '<form id="checkout" action=
class FD_Braintree_Form
{
public function fd_bt_form()
{
echo
'<form id="checkout" action="/process-trans.php" method="post">
<p>
<label><font size="5">Amount:</font></label>
<input type="text" size="4" name="amount" />
</p>
<div id="payment-form"></div>
<input type="submit" value="Pay" />
</form>';
}
}
class Find_Do_For_Anspress
{
add_action('ap_form_bottom_ask_form', array( $this, 'fd_bt_form_html')); //This is where I use the action hook to insert my code into the plugin's form_footer()
public function fd_bt_form_html()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'dropin', {
container: 'payment-form',
});
</script>
<?php
$class_bt_form = new FD_Braintree_Form();
$bt_form = $class_bt_form->fd_bt_form();
echo $bt_form;
}
}
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();
}
private function form_footer()
{
ob_start();
/**
* ACTION: ap_form_bottom_[form_name]
* action for hooking captcha and extar fields
* @since 2.0.1
*/
do_action('ap_form_bottom_'. $this->name);
$this->output .= ob_get_clean();
$this->output .= '<button type="submit" class="ap-btn ap-btn-submit">'.$this->args['submit_button'].'</button>';
if(@$this->args['show_cancel'] === true)
$this->output .= '<button type="button" class="ap-btn ap-btn-cancel">'.__('Cancel', 'ap').'</button>';
$this->output .= '</form>';
}
function ap_post_upload_hidden_form(){
if(ap_opt('allow_upload_image'))
return '<form id="hidden-post-upload" enctype="multipart/form-data" method="POST" style="display:none">
<input type="file" name="post_upload_image" class="ap-upload-input">
<input type="hidden" name="ap_ajax_action" value="upload_post_image" />
<input type="hidden" name="ap_form_action" value="upload_post_image" />
<input type="hidden" name="__nonce" value="'.wp_create_nonce( 'upload_image_'.get_current_user_id()).'" />
<input type="hidden" name="action" value="ap_ajax" />
</form>';
}
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
</div>
插件附带的“Post question”按钮不起作用,我怀疑这是由于第二个表单的存在
我所尝试的:
class FD_Braintree_Form
{
public function fd_bt_form()
{
echo
'<form id="checkout" action="/process-trans.php" method="post">
<p>
<label><font size="5">Amount:</font></label>
<input type="text" size="4" name="amount" />
</p>
<div id="payment-form"></div>
<input type="submit" value="Pay" />
</form>';
}
}
class Find_Do_For_Anspress
{
add_action('ap_form_bottom_ask_form', array( $this, 'fd_bt_form_html')); //This is where I use the action hook to insert my code into the plugin's form_footer()
public function fd_bt_form_html()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'dropin', {
container: 'payment-form',
});
</script>
<?php
$class_bt_form = new FD_Braintree_Form();
$bt_form = $class_bt_form->fd_bt_form();
echo $bt_form;
}
}
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();
}
private function form_footer()
{
ob_start();
/**
* ACTION: ap_form_bottom_[form_name]
* action for hooking captcha and extar fields
* @since 2.0.1
*/
do_action('ap_form_bottom_'. $this->name);
$this->output .= ob_get_clean();
$this->output .= '<button type="submit" class="ap-btn ap-btn-submit">'.$this->args['submit_button'].'</button>';
if(@$this->args['show_cancel'] === true)
$this->output .= '<button type="button" class="ap-btn ap-btn-cancel">'.__('Cancel', 'ap').'</button>';
$this->output .= '</form>';
}
function ap_post_upload_hidden_form(){
if(ap_opt('allow_upload_image'))
return '<form id="hidden-post-upload" enctype="multipart/form-data" method="POST" style="display:none">
<input type="file" name="post_upload_image" class="ap-upload-input">
<input type="hidden" name="ap_ajax_action" value="upload_post_image" />
<input type="hidden" name="ap_form_action" value="upload_post_image" />
<input type="hidden" name="__nonce" value="'.wp_create_nonce( 'upload_image_'.get_current_user_id()).'" />
<input type="hidden" name="action" value="ap_ajax" />
</form>';
}
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
</div>
我删除了我添加的代码中的一些片段,试图找出导致这种情况的原因,最终归结为DropIn的表单代码本身。此页面上的第二个表单出现问题
我的问题:当一页上有两张表格时,什么会导致提交问题
注意-我使用一个动作挂钩将代码插入一个函数,该函数将自己描述为主插件的表单页脚。我觉得这是一个表单嵌套问题 创建大脑树表单的my函数:
class FD_Braintree_Form
{
public function fd_bt_form()
{
echo
'<form id="checkout" action="/process-trans.php" method="post">
<p>
<label><font size="5">Amount:</font></label>
<input type="text" size="4" name="amount" />
</p>
<div id="payment-form"></div>
<input type="submit" value="Pay" />
</form>';
}
}
class Find_Do_For_Anspress
{
add_action('ap_form_bottom_ask_form', array( $this, 'fd_bt_form_html')); //This is where I use the action hook to insert my code into the plugin's form_footer()
public function fd_bt_form_html()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'dropin', {
container: 'payment-form',
});
</script>
<?php
$class_bt_form = new FD_Braintree_Form();
$bt_form = $class_bt_form->fd_bt_form();
echo $bt_form;
}
}
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();
}
private function form_footer()
{
ob_start();
/**
* ACTION: ap_form_bottom_[form_name]
* action for hooking captcha and extar fields
* @since 2.0.1
*/
do_action('ap_form_bottom_'. $this->name);
$this->output .= ob_get_clean();
$this->output .= '<button type="submit" class="ap-btn ap-btn-submit">'.$this->args['submit_button'].'</button>';
if(@$this->args['show_cancel'] === true)
$this->output .= '<button type="button" class="ap-btn ap-btn-cancel">'.__('Cancel', 'ap').'</button>';
$this->output .= '</form>';
}
function ap_post_upload_hidden_form(){
if(ap_opt('allow_upload_image'))
return '<form id="hidden-post-upload" enctype="multipart/form-data" method="POST" style="display:none">
<input type="file" name="post_upload_image" class="ap-upload-input">
<input type="hidden" name="ap_ajax_action" value="upload_post_image" />
<input type="hidden" name="ap_form_action" value="upload_post_image" />
<input type="hidden" name="__nonce" value="'.wp_create_nonce( 'upload_image_'.get_current_user_id()).'" />
<input type="hidden" name="action" value="ap_ajax" />
</form>';
}
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
</div>
class-FD\u-Braintree\u表单
{
公共功能fd_bt_表单()
{
回音
'
数量:
';
}
}
生成大脑树表单的my函数:
class FD_Braintree_Form
{
public function fd_bt_form()
{
echo
'<form id="checkout" action="/process-trans.php" method="post">
<p>
<label><font size="5">Amount:</font></label>
<input type="text" size="4" name="amount" />
</p>
<div id="payment-form"></div>
<input type="submit" value="Pay" />
</form>';
}
}
class Find_Do_For_Anspress
{
add_action('ap_form_bottom_ask_form', array( $this, 'fd_bt_form_html')); //This is where I use the action hook to insert my code into the plugin's form_footer()
public function fd_bt_form_html()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'dropin', {
container: 'payment-form',
});
</script>
<?php
$class_bt_form = new FD_Braintree_Form();
$bt_form = $class_bt_form->fd_bt_form();
echo $bt_form;
}
}
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();
}
private function form_footer()
{
ob_start();
/**
* ACTION: ap_form_bottom_[form_name]
* action for hooking captcha and extar fields
* @since 2.0.1
*/
do_action('ap_form_bottom_'. $this->name);
$this->output .= ob_get_clean();
$this->output .= '<button type="submit" class="ap-btn ap-btn-submit">'.$this->args['submit_button'].'</button>';
if(@$this->args['show_cancel'] === true)
$this->output .= '<button type="button" class="ap-btn ap-btn-cancel">'.__('Cancel', 'ap').'</button>';
$this->output .= '</form>';
}
function ap_post_upload_hidden_form(){
if(ap_opt('allow_upload_image'))
return '<form id="hidden-post-upload" enctype="multipart/form-data" method="POST" style="display:none">
<input type="file" name="post_upload_image" class="ap-upload-input">
<input type="hidden" name="ap_ajax_action" value="upload_post_image" />
<input type="hidden" name="ap_form_action" value="upload_post_image" />
<input type="hidden" name="__nonce" value="'.wp_create_nonce( 'upload_image_'.get_current_user_id()).'" />
<input type="hidden" name="action" value="ap_ajax" />
</form>';
}
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
</div>
为Ansu Press查找
{
add_action('ap_form_bottom_ask_form',array('this,'fd_bt_form_html');//在这里,我使用操作挂钩将代码插入插件的form_footer()
公共函数fd_bt_form_html()
{
$class_bt_token=new Braintree_ClientToken();
$clientToken=$class_bt_token->generate();
?>
braintree.setup(
'',
“下降”{
集装箱:'付款单',
});
编辑:本例中的问题是,您使用的操作钩子正在将表单放入插件的表单中。您需要使用不同的操作钩子(或者您需要使用此操作钩子)
您正在使用的插件没有提供适当的操作挂钩,无法将表单放置在您试图放置它的位置(在ask_表单之后)。您必须修改插件代码才能使其正常工作。如果您愿意修改插件代码,您可以这样做:
修改插件表单页脚方法:
private function form_footer()
{
ob_start();
/**
* ACTION: ap_form_bottom_[form_name]
* action for hooking captcha and extar fields
* @since 2.0.1
*/
do_action('ap_form_bottom_'. $this->name);
$this->output .= ob_get_clean();
$this->output .= '<button type="submit" class="ap-btn ap-btn-submit">'.$this->args['submit_button'].'</button>';
if(@$this->args['show_cancel'] === true)
$this->output .= '<button type="button" class="ap-btn ap-btn-cancel">'.__('Cancel', 'ap').'</button>';
$this->output .= '</form>';
//MODIFICATION added action
do_action('ap_form_aftercustom_'. $this->name);
}
private函数表单_footer()
{
ob_start();
/**
*操作:ap\U表单\U底部\u[表单\u名称]
*钩住captcha和extar字段的操作
*@自2.0.1起
*/
do_action('ap_form_bottom_.$this->name);
$this->output.=ob_get_clean();
$this->output.=''.$this->args['submit_button'].';
如果(@$this->args['show\u cancel']==true)
$this->output.=''.'取消''ap');
$this->output.='';
//修改附加动作
do_action('ap_form_After Custom_.$this->name);
}
然后,修改fd_bt_form_html函数:
class Find_Do_For_Anspress
{
//MODIFICATION use the new action
add_action('ap_form_aftercustom_ask_form', array( $this, 'fd_bt_form_html')); //This is where I use the action hook to insert my code into the plugin's form_footer()
public function fd_bt_form_html()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'dropin', {
container: 'payment-form',
});
</script>
<?php
$class_bt_form = new FD_Braintree_Form();
$bt_form = $class_bt_form->fd_bt_form();
echo $bt_form;
}
}
为Ansu Press查找
{
//修改使用新操作
add_action('ap_form_aftercustom_ask_form',array('this,'fd_bt_form_html'));//在这里,我使用操作挂钩将代码插入插件的表单页脚()
公共函数fd_bt_form_html()
{
$class_bt_token=new Braintree_ClientToken();
$clientToken=$class_bt_token->generate();
?>
braintree.setup(
'',
“下降”{
集装箱:'付款单',
});
是否使用1按钮提交2个表单?保存所有更改,将代码状态恢复到开始之前的状态,并查看是否存在问题。能否验证HTML?您可能有不匹配的标记。您还应检查表单是如何提交的,您可能需要在表单上放置不同的id或类按钮。如果你发布你的代码会有帮助。是的,发布一些代码会有很大帮助。我已经修改了我的答案,为你提供了一个有效的解决方案。但是,你必须修改插件的代码(1行)是的,我也认为这是示例#1中的问题。看看我刚刚做的编辑-我添加了插件附带的表单页脚代码。其中是我使用的动作挂钩。从你上传的代码中,我看不到第二个表单在任何地方被使用。(请参阅我对你原始问题的评论)。我可能需要查看AnsPress\u表单
类和ap\u post\u upload\u hidden\u表单
函数。哦,我很抱歉。我遗漏了实际使用动作挂钩的位置。我会编辑。嗯。AnsPress\u表单
类代码非常长…关于隐藏表单的主题,我为它添加了函数。似乎不得不这样做处理图像上传?不幸的是,PHP的本质意味着很多代码都不够优秀。让我试着想想/找到一个编写良好的PHP程序,你可以用它作为例子。平衡的API是体面的iirc(),但它们看起来很复杂。(免责声明,下面的产品是我写的):ActiveWAFL框架()有我认为写得非常好的OO PHP。下面是我在这个主题上做的一个旧演示:尽管如果我再做一次演示,我会修改我的一些陈述。