2013-02-13 77 views
0

當我導航到頁面時,爲什麼send()函數會自動調用?gsp mail plugin autosending

我希望能夠查看GSP頁面,在幾個文本字段填寫,然後調用與動作提交「發送」

這是我的GSP文件

<%@ page contentType="text/html;charset=UTF-8" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> 
<meta name="layout" content="main"/> 
<title>Contact Form</title> 
</head> 
<body> 
<g:form name="contactForm" action = "send"> 
    <g:render template = "contactFormFields"/> 
    <g:actionSubmit value = "submit" action = "send"/> 
</g:form> 
</body> 
</html> 

這是contactFormFields模板

<g:select name = 'subject' from = '${EmailService.options}' noSelection='Topic'/> 

Contact Name: <g:textField name = "contact"/> 
Contact Number: <g:textField name = "phone"/> 
Contact Email: <g:textField name = "email"/> 
Aditional Information: 
<g:textArea name = "information" rows="5" cols="40"/> 

EmailServiceController

class EmailServiceController { 

    def defaultAction = "contactService" 

    def send() { 
     sendMail(){ 
      to "[email protected]" 
      from params.email 
      subject params.subject 
      body params.information 
     } 
    } 
} 
調用服務

域類

class EmailService { 

    static constraints = { 
     def options = new ArrayList() 
     options.push("Qestions about service") 
     options.push("Feedback on performed service") 
     options.push("Other") 
     options.push("Why am I doing this") 
    } 
} 

GSP

<div class="banner"> 
    <h1>My HVAC company</h1> 
    <a href = "javascript: contactPop()"> Contact me today!</a> 
    <a href = "services">Services</a> 
    <a href = "emailService">Have Me Contact You!</a> 
</div> 
+0

您可以添加更多關於哪個動作加載此表單的上下文嗎? – uchamp 2013-02-13 06:43:38

+0

@uchamp我添加了領域類和div的鏈接位於 – 2013-02-13 12:11:45

回答

1

你沒有contactService行動在EmailServiceController因此它可能是治療send()作爲默認操作,當你鏈接到控制器沒有行動名稱。嘗試添加一個空的contactService動作

def contactService() { } 
+0

好抓住,但現在它說選項必須是一個集合(我不知道該怎麼做)。我正在嘗試使用grails來簡化它的過程,但我正在學習它是一個全新的野獸 – 2013-02-13 13:18:09

+0

@MattWestlake如上面所寫,您已將'options'聲明爲您的'constraints'塊內的局部變量域名類(順便說一句名字非常糟糕 - 你只能真正使用'服務'後綴來代替服務,而不是域類)。我不確定你想要達到的目標,但是如果選項列表是固定的,那麼可能更容易將它們聲明在GSP中,或者將它們放在'src/java'的枚舉中,而不是嘗試使用一個域類。 – 2013-02-13 13:25:43