Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向多个忍者表单提交添加$timestamp_Php_Ninja Forms - Fatal编程技术网

Php 向多个忍者表单提交添加$timestamp

Php 向多个忍者表单提交添加$timestamp,php,ninja-forms,Php,Ninja Forms,我已经成功地为一个Ninja表单提交添加了$timestamp,但不确定如何扩展下面的代码,以便在多个表单上工作 这是适用于单个忍者形态的代码 <?php /* Plugin Name: Time Stamp */ function my_ninja_forms_date_code(){ //Declare $ninja_forms_processing as a global variable. global $ninja_forms_processing; //

我已经成功地为一个Ninja表单提交添加了$timestamp,但不确定如何扩展下面的代码,以便在多个表单上工作

这是适用于单个忍者形态的代码

<?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_forms_processing->update_field_值(41,$timestamp)中的忍者表单id号和41;从隐藏字段id号中获取


任何建议/指导都是非常受欢迎的。

有两个
您是否尝试调试代码以查看代码是否达到语句要求?当我使用添加的elseif语句运行代码时,代码变为空白501服务器错误在没有elsif语句的情况下工作正常,但只提供一种忍者形式。我正在尝试扩展代码以服务于多个表单,这就是我遇到的问题。从我的角度来看,代码中没有错误。唯一需要检查的是代码的逻辑。也许为了检查表单_id是否真的是6,或者elseif块中的硬编码43是否是有效的数字,我回到我的服务器并将php错误设置为on,然后运行上面的代码并得到以下错误。“解析错误:语法错误,意外‘你能在提到的文件中粘贴代码的第5行吗?’很好地发现了,因为看不到明显的东西,现在感觉很傻。现在工作起来像做梦一样。非常感谢。”much@AndrewPaton很乐意帮忙