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.

Form Questions /

send form


Reply


3 Posts   1377 Views

Avatar
snaip

Community Member, 180 Posts

29 December 2008 at 11:27am

Edited: 29/12/2008 11:28am

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 ?

Avatar
UncleCheese

4085 Posts

29 December 2008 at 12:55pm

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.

Avatar
snaip

Community Member, 180 Posts

31 December 2008 at 1:06pm

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();
...