为多个Ninja表单提交添加$ timestamp

时间:2016-01-20 13:23:54

标签: php ninja-forms

我已设法在单个Ninja Form提交中添加$ timestamp,但不确定如何扩展以下代码,因此可以使用多个表单。

这是适用于单个Ninja表单的代码

<?php
/*
Plugin Name: Time Stamp
*/
function my_ninja_forms_date_code(){
    //Declare $ninja_forms_processing as a global variable.
    global $ninja_forms_processing;
    //only process this code on the form ID 1
    $form_id = $ninja_forms_processing->get_form_ID();
    if( $form_id == 2 ){
        //sets timestamp variable to current time
        $timestamp = date('G:i:s');
        //Update the hidden field value for the field with an ID of 41 to the
current time.
        $ninja_forms_processing->update_field_value( 41, $timestamp );
    }
}
add_action( 'ninja_forms_process', 'my_ninja_forms_date_code' );
?>

我曾尝试为两个表单添加一个elseif条件,但未被接受,请参阅下面的代码:

<?php
/*
Plugin Name: Example Plugin
*/
<?php
function my_ninja_forms_date_code(){
    //Declare $ninja_forms_processing as a global variable.
    global $ninja_forms_processing;
    //only process this code on the form ID 1
    $form_id = $ninja_forms_processing->get_form_ID();

    if( $form_id == 2 ){
        //sets timestamp variable to current time
        $timestamp = date('G:i:s');
        //Update the hidden field value for the field with an ID of 3 to the current time.
        $ninja_forms_processing->update_field_value( 41, $timestamp );
    }
    elseif ( $form_id == 6 ){
        //sets timestamp variable to current time
        $timestamp = date('G:i:s');
        //Update the hidden field value for the field with an ID of 43 to the current time.
        $ninja_forms_processing->update_field_value( 43, $timestamp );
    }
}
add_action( 'ninja_forms_process', 'my_ninja_forms_date_code' );
?>

$ form_id指的是Ninja表格ID no和$ ninja_forms_processing-&gt; update_field_value中的41(41,$ timestamp);取自隐藏的Field id no。

欢迎任何建议/指导。

1 个答案:

答案 0 :(得分:0)

您提到的文件中有两个<?php开头标记,只需删除第二个,您的代码就可以正常运行而不会出错。