将 $timestamp 添加到多个 Ninja 表单提交

Adding $timestamp to Multiple Ninja Form submissions

我已经设法将 $timestamp 添加到单个 Ninja 表单提交中,但不确定如何扩展下面的代码以便处理多个表单。

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

<?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 Form ID no和$ninja_forms_processing->update_field_value( 41, $timestamp )中的41;取自隐藏的Field id no.

欢迎任何suggestions/guidance。

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