我有三个文件:submit.php
(一页),validation.php
, script.php
我正试图通过wp_insert_post()
作用
然而,我不知道该将函数放在哪里,因为我在validation.php
或者,如果我把它放在那个文件中,它会导致一个错误,因为它不能传递wordpress函数。
我试过玩success
在$.ajax
但是自从die()
函数都会导致它成功,不能触发创建帖子。
有谁有更好的解决方案吗?
在submit.php
我有一张表格:
<div class="" id="response"></div>
<form id="form_ticket_submit" method="post">
<label for="form_ticket_subject">Subject of issue</label>
<input id="form_ticket_subject" name="form_ticket_subject" type="text">
<label for="form_ticket_content">Post</label>
<textarea id="form_ticket_content" name="form_ticket_content"></textarea>
<label for="form_ticket_tax_stage">Select Stage</label>
<select id="form_ticket_tax_stage" name="form_ticket_tax_stage">
<option value="">Select one</option>
<?php foreach ($form_ticket_tax_cat_stage as $form_cat_stage) { echo \'<option value="\' . $form_cat_stage->slug . \'">\'. $form_cat_stage->name . \'</option>\'; } ?>
</select>
<input hidden="hidden" id="form_ticket_meta_date" name="form_ticket_meta_date" type="text" readonly="readonly" value="<?php echo get_date_from_gmt( date( \'Y-m-d H:i:s\' ), \'jS \\of F, Y H:i:s\' ); ?>">
<input hidden="hidden" id="form_ticket_meta_user_name" name="form_ticket_meta_user_name" type="text" readonly="readonly" value="<?php echo $form_ticket_current_user_name; ?>">
<input hidden="hidden" id="form_ticket_meta_user_email" name="form_ticket_meta_user_email" type="text" readonly="readonly" value="<?php echo $form_ticket_current_user_email; ?>">
<input name="submit" type="submit" value="Submit Ticket" />
</form>
在
script.js
我有:
<script>
$(function(){
$("#mb_ticket_submit").submit(function(a){
a.preventDefault();
$.ajax({
method: "POST",
url: "validation.php",
data: {
mb_ticket_subject: $("#mb_ticket_subject").val(),
mb_ticket_content: $("#mb_ticket_content").val(),
mb_ticket_tax_stage: $("#mb_ticket_tax_stage option:selected").val(),
mb_ticket_tax_application: $("#mb_ticket_tax_application option:selected").val(),
mb_ticket_meta_date: $("#mb_ticket_meta_date").val(),
mb_ticket_meta_user_name: $("#mb_ticket_meta_user_name").val(),
mb_ticket_meta_user_email: $("#mb_ticket_meta_user_email").val(),
},
success: function(a){ $("div#response").show().html(a); },
});
})
});
</script>
最后
validation.php
具有以下内容(已清理$var,并从其
$_POST[]
:
if( empty($form_ticket_meta_user_name) ) { die( \'Doesn\\\'t look like you have logged in properly\'; ) }
if( empty($form_ticket_meta_user_email) ) { die( \'Doesn\\\'t look like you have logged in properly\'; ) }
if( !empty($form_ticket_meta_user_email) ){ if( !filter_var($form_ticket_meta_user_email, FILTER_VALIDATE_EMAIL) ) { die( \'Doesn\\\'t look like your email address is formatted properly. Contact your administrator.\' ); } }
if( empty($form_ticket_subject) ) { die( \'No subject\' ); }
if( empty($form_ticket_content) ) { die( \'No content\' ); }
if( empty($form_ticket_tax_stage) ) { die( \'No stage\'); }
if( empty($form_ticket_tax_application) ) { die( \'No app\' ); }
if( empty($form_ticket_tax_priority) ) { die( \'No priority\' ); }
if( empty($form_ticket_tax_location) ) { die( \'No location\' ); }
谢谢:)