【发布时间】:2016-05-18 16:29:36
【问题描述】:
所以我在网上查了一下,在这里发现了一些关于它的问题,但似乎没有什么适合我的情况。
我有一个表单,它应该调用页面上设置的函数。
表单的html如下:
<form method="post" action="">
<textarea id="input-box" placeholder="What's on your mind?" maxlength="10000" name="quick-post-area" class="col-md-offset-2 col-md-6"></textarea>
<input type="submit" value="Post" class="col-md-2" id="quick-post-submit">
</form>
和功能:
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
$author_id = 1;
$slug = 'post';
global $current_user;
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$pollq_question = wp_kses_post( trim( $_POST['pollq_question'] ) );
$post_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'closed',
'post_author' => $current_user->ID,
'post_name' => $slug,
'post_title' => 'Posted By:' . $current_user->ID,
'post_status' => 'publish',
'post_type' => 'post',
'post_content' => $_POST['quick-post-area']
)
);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // end programmatically_create_post
最后是我试图用来调用函数的 isset:
if(isset($_POST['submit']))
{
quick_post();
}
有人知道我需要改变什么才能触发它吗?
【问题讨论】:
-
不,你不需要使用 ajax。
-
另外,如果您不介意刷新页面,
isset post submit将在其上查找名称为submit的对象,因此请将name="submit"添加到您在表单上提交的输入中 -
这不是完整的功能代码吗?因为它缺少基本知识
function quick_post(){ ...