Jump to:

1976 Posts in 1306 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » send form

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

Page: 1
Go to End
Author Topic: 1295 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    send form Link to this post

    hi

    how to send the form ?
    i have

    class TourPage_Controller extends Page_Controller {
    ...

    function MyForm() {
    // Create fields
    $fields = new FieldSet(
    new TextField('FirstName', 'First name'),
    new EmailField('Email', 'Email addres')
    );

    function forTemplate() {
    return $this->renderWith(array(
    $this->class,
    'Form'
    ));
    }

    // Create actions
    $actions = new FieldSet(
    new FormAction('doMyForm', 'Send')
    );

    return new Form($this, 'MyForm', $fields, $actions);
    }

    function doMyForm($data, $form) {
    $email = new Email_Template(
    $data['Email'],
    'my@gmail.com',
    'good work'
    );
    $email->ss_template = 'MyForm';
    $email->populateTemplate(array (
    'Name' => $data['FirstName'],
    'Email' => $data['Email'],
    ));
    $email->send();
    }

    ...
    }

    but it doesn't work
    i have MyForm.ss in templates/email but i don't know what it should contains
    could you give me some example code for my form which i should put into MyForm.ss ?

  • UncleCheese
    Avatar
    4085 Posts

    Re: send form Link to this post

    To make things easier on yourself you can just do $email->populateTemplate($data);

    Then, all the keys of the $data array are available on your template. For instance, if you had a textfield with the name 'Name', you could call $Name on your template.

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: send form Link to this post

    nothing

    i think that this

    $actions = new FieldSet(
    new FormAction('doMyForm', 'Send')
    );

    doesn't work

    i put the basic code in doMyForm function like this

    function MyForm() {
    echo "hello";
    }

    and nothing happends
    i get the blank site

    i tried with phpmailer
    it works but only if i put the code outside form the class

    class TourPage extends Page {
    ...
    }

    class TourPage_Controller extends Page_Controller {
    ...
    }

    require("class.phpmailer.php");
    $mail = new PHPMailer();
    ...

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