When I navigate to the page, why is the send() function being called automatically?
I want to be able to view the gsp page, fill in a few text fields, and THEN call the submit with an action of "send"
This is my gsp file
<%@ 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>
This is the contactFormFields template
<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
}
}
}
domain class
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 that calls the service
<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>
You don't have a contactService
action in your EmailServiceController
so it's probably treating send()
as the default action when you link to the controller with no action name. Try adding an empty contactService
action
def contactService() { }