2015-07-28 88 views
0

我有一個使用Gravity Forms的WordPress網站,並且在這個表單中我有一個字段,需要用戶輸入一個特殊的10位數字代碼,以匹配代碼數據庫(有20個數字代碼這些代碼)。如果輸入的代碼與20個代碼中的一個匹配,則可以繼續提交表單。如果不匹配,則無法繼續。WordPress Gravity Form Field Validation

請告知如何創建一個PHP函數來實現這個功能?

非常感謝

+2

到目前爲止您嘗試了什麼?你有沒有寫過任何代碼?你是否熟悉PHP和編寫WordPress插件?顯示你已經做了研究,並在你的問題中付出努力將增加用戶將幫助你的可能性。 – user1438038

回答

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 
));