2012-02-29 111 views
1

我使用嵌入HTML5文檔的XFBML。我已經按照Facebook網站上的「註冊高級使用」文檔中提供的說明設置了客戶端驗證,但它僅在模糊時顯示錯誤,並且在單擊「註冊」按鈕時不會驗證(所以如果我填寫一個字段錯誤,並在另一個元素上點擊外部,它會顯示錯誤,但我可以點擊註冊按鈕,並且它會註冊我)。使用Facebook註冊的客戶端驗證XFBML

我已經在JS調試器中追蹤了它,並添加了警報/日誌語句,而我的validate_registration函數僅被稱爲onblur,並且從未單擊Register按鈕。

任何人看到這種行爲,並知道我在這裏失蹤? Facebook上的「註冊高級使用」的實例可以完美地工作,所以我知道我在某個地方犯了一個錯誤。

我XFBML標籤是這樣的:

<div class="fb-registration" 
    onvalidate="validate_registration" 
    fields="[ 
     {'name': 'name'}, 
     {'name': 'first_name'}, 
     {'name': 'gender'}, 
     {'name': 'email'}, 
     {'name': 'user_type', 'description': 'Are you a?', 'type': 'select', 
     'options': { 
      'parent': 'Parent/Guardian looking for childcare', 
      'sitter': 'Babysitter/Nanny looking for sitting jobs' 
     } 
     }, 
     {'name': 'zip_code', 'description': 'Zip code', 'type': 'text'}, 
     {'name': 'over_eighteen', 'description': 'I am at least 18 years old', 'type': 'checkbox' } 
    ]" 
    fb_only="true" 
    redirect-uri="<%= parse_fb_connect_signed_request_users_url %>" 
    width="530"> 
    </div> 

和我的驗證功能是這樣的:

function validate_registration (custom_fields) { 
    var errors = {}, 
     regexZipCode = /^\d\d\d\d\d$/; 

    console.log("in validate_registration"); 

    if (custom_fields.user_type !== 'parent' && custom_fields.user_type !== 'sitter') { 
     errors.user_type = "Select either Parent or Sitter"; 
    } 

    if (! regexZipCode.test(custom_fields.zip_code)) { 
     errors.zip_code = 'Enter your 5-digit U.S. zip code'; 
    } 

    if (! custom_fields.over_eighteen) { 
     errors.over_eighteen = 'You must be at least 18 years old to use this site!'; 
    } 

    return errors; 
} 

回答

3

所以,別提這個。

我收到消息「您剛剛使用您的Facebook帳戶註冊了X. 如果您不打算這樣做,您可以在下面撤消此操作。並認爲這意味着我已經註冊。但是,如果我點擊「繼續」,它會向我顯示所有驗證錯誤,所以它確實工作正常 - 直到最後一步之後纔會驗證。

+0

是的,有趣的如何在Facebook發言「你剛剛註冊」並不意味着「你剛剛註冊」。我今天花了幾個小時試圖解決這個問題,並在放棄之前看到你的帖子。謝謝! – danorton 2012-03-03 04:33:06