Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » [Solved] Contact form not working properly inside template loop

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

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

Page: 1
Go to End
Author Topic: 194 Views
  • Anytech
    Avatar
    Community Member
    2 Posts

    [Solved] Contact form not working properly inside template loop Link to this post

    Hello,

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

    The site is a parallax site http://www.anytech.co.nz/fdc

    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(
    'ContactForm'
    );
       
    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);
       $form->forAjaxTemplate();
       return $form;
    }
       
       
       function SendContactForm($data, $form) {
          Debug::dump($this->requestParams);
          
    //Set data
    $From = $data['emailContact'];
    $To = 'omikaman@gmail.com';
    $Subject = "Website Contact message";
    $email = new Email($From, $To, $Subject);
    //set template
    $email->setTemplate('ContactEmail');
    //populate template
    $email->populateTemplate($data);
    //send mail
    $email->send();
          Page_Controller::redirect($this->Link("?success=1"));
    }
    }

    Page.ss

    <% 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">
                      $Content
                   </div>
                <% end_loop %>
                <% loop $MenuCategorys %>
                   <% if $PreColumns > 0 %>
                   <div class="grid_$PreColumns alpha omega">
                   </div>
                   <% end_if %>
                   <div class="grid_$Columns alpha omega">
                            <h2>$Category</h2>   
                            <ul>
                            <% loop $MenuItems %>
                               <li>$ItemName <br /><% if $Description %>$Description<% end_if %>$Price<br /><br /></li>
                            <% end_loop %>   
                            </ul>
                   </div>       
                <% end_loop %>
                <% loop getCP() %>
                   <% loop $Up.Up.ContactForm %>
           <form name="contactForm" $FormAttributes>
    <h2>Contact Form</h2>
              <div class="inputsrow clearfix">
                 <div class="inputicon">
                    <span></span>
    $Fields.FieldByName(nameContact)
                 </div>
                 <div class="inputicon icon2">
                    <span></span>
    $Fields.FieldByName(emailContact)
                 </div>
                 <div class="inputicon icon3">
                    <span></span>
    $Fields.FieldByName(urlContact)
                 </div>
              </div>
              <div class="commenttext">
       $Fields.FieldByName(obsContact)
              </div>

    <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">
                 <span></span>
              </div>
           </form>
    <% end_loop %>
                <% end_loop %>
                
          </div>
       </div>
       
    <% end_loop %>

  • Anytech
    Avatar
    Community Member
    2 Posts

    Re: [Solved] Contact form not working properly inside template loop Link to this post

    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.

    194 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.