2011-05-12 74 views
0

我正在按照如何驗證form fields的教程進行操作,但它僅在一個字段中顯示它。我如何驗證並顯示多個字段的錯誤?電梯錯誤檢查多個表單字段

我嘗試以下 - 但它總是成功,並做了重定向 - 無論錯誤:

def process() = { 
    if (patientName == "Joe") { 
     S.error("patientName", "Joe not allowed!") 
    } 
    if (birthdate == "22/22/2222") { 
     S.error("birthdate", "Invalid date!") 
    } 
    S.notice("Success! You entered Patient name: " + patientName); S.redirectTo("/")  
} 

回答

1

哈!我想到了。美麗。

def process() = { 
    if (patientName == "Joe") { 
     S.error("Joe not allowed!") 
    } 
    if (birthdate == "22/22/2222") { 
     S.error("birthdate", "Invalid birthdate!") 
    } 

    S.errors match { 
     case Nil =>S.notice("Patient name: " + patientName); S.redirectTo("/") 
     case _ => 
    } 
    }