Jump to:

23477 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Form builder link up with static form

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: 541 Views
  • lozhowlett
    Avatar
    Community Member
    146 Posts

    Form builder link up with static form Link to this post

    Hi everyone

    I have made a good start to the following website http://www.neseo.co.uk/

    There is a form on the right hand side, which is static in the template include. However I obviously want this to be Form2Mail and create a backup copy of the data entered in the backoffice system.

    I dont really know where to start with this, does anyone have some ideas?

    Thanks very much in advance for any help.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Form builder link up with static form Link to this post

    Take a look at http://doc.silverstripe.org/sapphire/en/topics/email

    You could create a data object to store a backup copy of the form in the Database while mailing it to its intended recipient. I use a similar system to handle product reviews.

    The Review DataObject looks like this

    class Review extends DataObject
    {
       static $db = array (
          'Date' => 'Date',
          'Name' => 'Text',
          'Email' => 'Text',
          'Title' => 'Text',
          'Location' => 'Text',
          'Rating' => 'Int',
          'Review' => 'HTMLText',
          'Approval' => 'Boolean'
       );
       
       static $has_one = array (
          'Product' => 'Product',
          'ColorProduct' => 'ColorProduct'
       );
       
       
       
       public function getCMSFields_forPopup()
       {
          $ratingArray = array (
                       '1' => '1',
                       '2' => '2',
                       '3' => '3',
                       '4' => '4',
                       '5' => '5'
                       );
          
          return new FieldSet(
             new CheckboxField('Approval'),
             new CalendarDateField('Date'),
             new TextField('Name'),
             new EmailField('Email'),
             new TextField('Title'),
             new TextField('Location'),
             new DropdownField('Rating','Rating',$ratingArray),
             new TextareaField('Review')
          );
       }
       

    }

    While the ReviewForm on the Product DataObject looks like this

    function UserProductReviewForm() {
    // Create fields
       
       
    $fields = new FieldSet(
                          new TextField('Name','Name:'),
                          new EmailField('Email','E-Mail Address:'),
                          new OptionsetField('Rating','Rating',array(
                                                          '1' => '1',
                                                          '2' => '2',
                                                          '3' => '3',
                                                          '4' => '4',
                                                          '5' => '5',
                                                          )
                                        ),
                          new TextField('Title','Review Title:'),
                          new TextareaField('Review'),
                          new HiddenField('ProductID', '', $this->ID),
                          new HiddenField('ProductName','',$this->Title)
    );
    // Create actions
    $actions = new FieldSet(
    new FormAction('doReview', 'Submit')
    );
          
          $form = new Form($this, 'UserProductReviewForm', $fields, $actions);
          $protector = SpamProtectorManager::update_form($form);
          
          if($protector) $protector->setFieldMapping('Name', 'Email', 'Title', 'Review');
       
       return $form;
       
    }

    function doReview($data, $form) {
    $review = new Review();
    $form->saveInto($review);
    $review->write();
       
        //Set data
        $From = "review@mywebsite.com";
        $To = "receiver@mywebsite.com";
        $Subject = "New Review for " . $data['ProductName'];
        $email = new Email($From, $To, $Subject,$body);
        //set template
        $email->setTemplate('ReviewEmail');
        //populate template
        $email->populateTemplate($data);
        //send mail
        $email->send();
        //return to submitted message
        Director::redirect(Director::baseURL(). "thank-you-for-your-review/");
        //return $this->Mailto;
    }


    You could also just replace the whole set/populate template section buy pushing the form fields into the $body

  • lozhowlett
    Avatar
    Community Member
    146 Posts

    Re: Form builder link up with static form Link to this post

    thanks very much... do you do any freelance? we are interested in getting a silverstripe developer on board. Cheers

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Form builder link up with static form Link to this post

    Haha I do, but I have an impending baby on the way and I don't want to commit to any major projects until I know how it will big wrench it'l throw in my freelance time

    But if you need some advice, feel free to contact me. http://designplusawesome.com

    541 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.