当我导航到页面时,为什么会自动调用 send() 函数?
我希望能够查看 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"/>
电子邮件服务控制器
class EmailServiceController {
def defaultAction = "contactService"
def send() {
sendMail(){
to "mygroovytest@gmail.com"
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>