WordPress重力表格字段验证

时间:2015-07-28 09:19:47

标签: php wordpress gravity-forms-plugin

我有一个使用Gravity Forms的WordPress网站,在这个表单中我有一个字段,需要一个特殊的10位数代码由用户输入,与代码数据库匹配(这些代码中有20个)。如果输入的代码与20个代码中的一个匹配,则他们可以继续提交表单。如果它不匹配则无法继续。

请告知如何创建实现此目的的PHP函数?

非常感谢

1 个答案:

答案 0 :(得分:0)

我写了一个你可能会觉得有帮助的片段。

http://gravitywiz.com/require-existing-value-submission-gravity-forms/

要根据需要使用此代码段,您需要设置一个新表单,用于存储20个代码。将单行文本字段添加到表单中。为每个代码添加一个条目。

在原始表单上,您现在可以配置代码段以检查有效代码的新表单的值。很高兴回答任何问题。

new GW_Value_Exists_Validation( array(
    'target_form_id'  => 613, // your original form ID where the codes will be validated
    'target_field_id' => 1,   // the field on your original form where the user should enter the code
    'source_form_id'  => 519, // the new form you will create to store your codes
    'source_field_id' => 1,   // the field on the new form that will store one code per submission
    'validation_message' => 'Hey! This isn\'t a valid reference number.' // the error message displayed if the user does not enter a valid code
) );