我已经设法将 $timestamp 添加到单个 Ninja Form 提交中,但不确定如何扩展下面的代码,以便在多个表单上工作。
这是适用于单个 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;取自隐藏的字段 ID 号。
任何建议/指导都将受到欢迎。