我对php很陌生,我的网站主题使用admin ajax发送查询表单,但admin ajax中没有相应的功能。php。我想知道如何创建它们。使用联系人表单的页面具有以下代码
if ( isset( $cs_post_request_form_option ) && $cs_post_request_form_option == \'on\' ) {
cs_user_conatct_form( $organizerID );
}
?>
在函数页面上,我有cs\\u user\\u conatct\\u form()的代码
if(!function_exists(\'cs_user_conatct_form\')){
function cs_user_conatct_form( $organizerID = \'\'){
$user_contact_form = get_the_author_meta( \'user_contact_form\', $organizerID );
if( $user_contact_form == \'1\') {
?>
<div class="csuser_info contactform">
<div id="cs_requestdetail">
<div class="rq-form">
<h5><?php esc_html_e(\'enquire now\',\'directory\');?></h5>
<div id="request-loading"></div>
<div class="request-message-type succ_mess" style="display:none"><p></p></div>
<form id="frm_request" name="frm_request" method="post" novalidate>
<ul>
<li><div class="rqform-text"><input type="text" placeholder="<?php _e(\'Name\',\'directory\');?>" name="<?php _e(\'request name\',\'directory\');?>" id="request_name" /></div></li>
<li><div class="rqform-text"><input type="text" placeholder="<?php _e(\'Email\',\'directory\');?>" name="<?php _e(\'request email\',\'directory\');?>" id="request_email"></div></li>
<li><div class="rqform-text"><input type="text" placeholder="<?php _e(\'Phone No\',\'directory\');?>" name="<?php _e(\'request number\',\'directory\');?>" id="request_number"></div></li>
<li><div class="rqform-text"><textarea placeholder="<?php _e(\'Message\',\'directory\');?>" name="<?php _e(\'request message\',\'directory\');?>" id="request_message" ></textarea>
<ul class="check-box" style="display:none">
<li>
<div class="checkbox">
<input type="checkbox" id="checkbox2" checked="checked" name="<?php _e(\'term condtions check\',\'directory\');?>">
</div>
</li>
</ul>
<input type="hidden" name="user_id" value="<?php echo intval( $organizerID );?>" />
<input type="hidden" name="action" value="cs_add_request" />
<input type="button" value="<?php _e(\'Submit\',\'directory\');?>" class="cs-bgcolor" onclick="cs_request_submission(\'<?php echo admin_url(\'admin-ajax.php\')?>\', \'<?php echo get_template_directory_uri()?>\',<?php $("#frm_request")[0].reset();?>);">
</div>
</li>
</ul>
</form>
</div>
</div>
</div>
<?php
}
}
}
等等。js我有以下代码
function cs_request_submission(admin_url,theme_url){
\'use strict\';
jQuery(".request-message-type").hide();
jQuery("#request-loading").html("<img src=\'"+theme_url+"/include/assets/images/ajax_loading.gif\' />");
jQuery(".request-message-type").html(\'\');
jQuery.ajax({
type:"POST",
url: admin_url,
dataType: "json",
data:jQuery(\'#frm_request\').serialize(),
success:function(response){
if (response.type == \'success\' ) {
jQuery("#request-loading").html(\'\');
jQuery(".request-message-type").html(response.message);
jQuery(".request-message-type").show();
jQuery("#request_name").val(\'\');
jQuery("#request_email").val(\'\');
jQuery("#request_number").val(\'\');
jQuery("#request_message").val(\'\');
jQuery(\'#checkbox2\').attr(\'checked\', false); // Unchecks it
jQuery("#frm_request").slideUp();
} else {
jQuery("#request-loading").html(\'\');
jQuery(".request-message-type").html(response.message);
jQuery(".request-message-type").show();
}
}
});
return false;
}
我想知道如何创建管理ajax函数,以及如何像mydomain一样发送页面url。com/adenquiry/postname上的表单可用。