2016-09-16 47 views
1

我創造新提交後前端的形式(我希望大多數人都熟悉它),用下面的代碼:acf_form()驗證和反饋

$options = array(
    'post_id' => 'new_post', 
     'new_post' => array(
     'post_type'  => 'post', 
     'post_status' => 'pending' 
    ), 
    'html_before_fields' => $html_before_fields, 
    'html_after_fields' => $html_after_fields, 
    'uploader' => 'basic', 
    'submit_value' => __("Create", 'domain'), 
    'updated_message' => __("Your post was submitted successfully! Please wait for it to be approved.", 'domain'), 
); 

acf_form($options); 

這裏是一個片段我的functions.php;

function _action_ssd_acf_submit_post_pre_save($post_id) { 

    if(empty($_POST['acf'])) { 
     return; 
    } 

    if (!isset($_POST['acf_post_submit'])) { // this is a hidden input field in the form 
     return; 
    } 

    if () { // some more checks here 
     wp_mail(); //removed parameters for cleaner code, I send email to the admin 
    } 

    if(empty(get_user_meta(get_current_user_id(), 'this_user_can_submit', true))) { 
     exit; 
     return; 
    } 


} 

add_action('acf/pre_save_post', '_action_ssd_acf_submit_post_pre_save'); 

如何阻止帖子保存,因爲它始終保存爲草稿?

另外,我似乎無法找到一種方法來改變update_message當提交錯誤。例如,如果用戶沒有所需的user_meta

所以,是的,我的問題是我無法停止提交帖子(如果出現驗證錯誤),並在頁面刷新後發送前端消息反饋。

回答

0

如果您想要發佈帖子,而不是設置爲草稿,則需要使用'post_status' => 'publish'而不是'post_status' => 'post'

+0

我在這裏寫代碼時犯了一個錯誤。發佈狀態''post_status'=>'發佈'是上面應該寫的那個。我的問題是我無法停止提交帖子(如果發生驗證錯誤),並在頁面刷新後發送前端消息反饋。 – Ziik