是否可以使用 file_get_contents() 为 Ninja Forms 运行服务器端验证?

问题描述

我一整天都在为我的项目的最后一部分而绞尽脑汁。我正在使用 Ninja Forms 并希望在提交表单之前验证字符串。我已经把它分解成几部分并使用简单的字符串检查进行了测试,它起作用了,但是当我尝试使用 file_get_contents() 函数时,它只是提交而不运行检查。文件 realtor_info.txt 包含以下内容:mikeoberdick@gmail.com - BP61AM。该页面位于此处:https://www.rhwarranty.com/realtor-quote/

add_filter( 'ninja_forms_submit_data','my_ninja_forms_submit_data');

function my_ninja_forms_submit_data( $form_data ) {
    $form_id = $form_data[ 'form_id' ];
    if ( $form_id = 4 ) {
        
        $email_field_id = 41;
        $coupon_field_id = 49;

        $email = $form_data['fields'][$email_field_id]['value'];
        $coupon = $form_data['fields'][$coupon_field_id]['value'];

        $string = $email . ' - ' . $coupon;
        $file = "https://rhwarranty.com/wp-content/themes/regal-home-warranty/stripe/realtor_info.txt";

        //check the file to see if the string exists
        if( strpos(file_get_contents($file),$string) !== false) {
            return $form_data;
        } else {
            $form_data['errors']['fields'][$coupon_field_id] = 'Something is not quite right here!';
        }
    }
}

对出了什么问题有任何想法吗?

解决方法

为什么要在 if 语句中给表单赋值?

或者如果 ( $form_id = 4 ) { 这应该是 if ( $form_id == 4 ) {