Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] Contact form not working properly inside template loop

Go to End

2 Posts   950 Views


Community Member, 2 Posts

3 March 2014 at 5:10pm


I am having trouble getting this thing working. I have been trying for hours!

The site is a parallax site

For some reason I cannot get this to work. I have the contact from working on other sites. It posts to /fdc/home/ContactForm which does not exist and I never receive any emails.

Any help is appreciated. Thanks.

Page.php (just the bottom bit)

class Page_Controller extends ContentController {
	public static $allowed_actions = array(
    function ContactForm() {
        // Create fields          
        $fields = new FieldList(
			new TextField('nameContact','Name','Name'),
			new TextField('urlContact','Website','Website'),
            new EmailField('emailContact','Email','Email'),
            new TextareaField('obsContact','Message','Message')
        // Create action
        $actions = new FieldList(new FormAction('SendContactForm', 'Send'));         
        // Create Validators
        //$validator = new RequiredFields();
        //return new Form($this, 'ContactForm', $fields, $actions);
		$form = new Form($this, 'ContactForm', $fields, $actions); 
      	return $form; 
	function SendContactForm($data, $form) {
        //Set data
        $From = $data['emailContact'];
        $To = '';
        $Subject = "Website Contact message";     
        $email = new Email($From, $To, $Subject);
        //set template
        //populate template
        //send mail

<% loop getPages() %>	
	<div class="slide" id="slide$Pos" data-slide="$Pos" <% if $ParallaxRatio %>data-stellar-background-ratio="$ParallaxRatio"<% end_if %>>
				<div class="container clearfix">
				<% loop getGridContent() %>
					<div class="grid_$Columns alpha omega">
				<% end_loop %>
				<% loop $MenuCategorys %>
					<% if $PreColumns > 0 %>
					<div class="grid_$PreColumns alpha omega">
					<% end_if %>
					<div class="grid_$Columns alpha omega">
								<% loop $MenuItems %>
									<li>$ItemName <br /><% if $Description %>$Description<% end_if %>$Price<br /><br /></li>
								<% end_loop %>	
				<% end_loop %>
				<% loop getCP() %>
					<% loop $Up.Up.ContactForm %> 
		            <form name="contactForm" $FormAttributes>             
                    <h2>Contact Form</h2>
		            	<div class="inputsrow clearfix">
			            	<div class="inputicon">
			            	<div class="inputicon icon2">
			            	<div class="inputicon icon3">
			            <div class="commenttext">
                    <input type="hidden" name="SecurityID" value="$SecurityID" class="hidden" id="Form_ContactForm_SecurityID" />
			            <input type="submit" class="btn5" id="contactSmbt" />
			            <div id="msgContact"></div>
			            <div id="contactLoader" class="loader">
                    <% end_loop %>
				<% end_loop %>
<% end_loop %>


Community Member, 2 Posts

3 March 2014 at 8:50pm

It looks like the code was correct but it needed flushing a few times!
Let me know if anyone needs to see more of the code to solve their problem.