Hi,
i try to create my own form. Everything works fine except my action is never reached. I derived the form class from Form because I want my own template to be used.
First I created a new page type called ContactFormPage:
class ContactFormPage extends Page {
}
class ContactFormPage_Controller extends Page_Controller {
public function init() {
parent::init ();
//setze die locale, damit das Suchform auf deutsch switcht
if ($this->dataRecord->hasExtension ( 'Translatable' )) {
i18n::set_locale ( $this->dataRecord->Locale );
}
}
public function ContactForm() {
return new ContactForm ( $this, 'Kontakt' );
}
function submit($data, $form) {
Debug::message("am i here?");
$this->redirect('EmailDanke');
/* $email = new Email('kontakt@schloss-open-air.de', 'rolf.staege@lumturo.net', 'Webseitenkontakt');
$email->setTemplate('EmailForm');
$email->populateEmail($data);
// $email->send();
*/
}
}
Then I created my form class as follows:
DEFINE ( 'TEXTFIELD_MAXLENGTH', 20 );
class ContactForm extends Form {
function __construct($controller, $name) {
if ($controller->getRequest ()->getVar ( 'recv_chef' ))
$rcc = new CheckboxField ( 'recv_chef', _t ( 'ContactForm.RECV_CHEF', 'geschaeftsleitung' ), 1 );
else
$rcc = new CheckboxField ( 'recv_chef', _t ( 'ContactForm.RECV_CHEF', 'geschaeftsleitung' ) );
if ($controller->getRequest ()->getVar ( 'recv_presse' ))
$rcp = new CheckboxField ( 'recv_presse', _t ( 'ContactForm.RECV_PRESSE', 'presse' ), 1 );
else
$rcp = new CheckboxField ( 'recv_presse', _t ( 'ContactForm.RECV_PRESSE', 'presse' ) );
if ($controller->getRequest ()->getVar ( 'recv_booking' ))
$rcb = new CheckboxField ( 'recv_booking', _t ( 'ContactForm.RECV_BOOKING', 'booking' ), 1 );
else
$rcb = new CheckboxField ( 'recv_booking', _t ( 'ContactForm.RECV_BOOKING', 'booking' ) );
if ($controller->getRequest ()->getVar ( 'recv_produktleitung' ))
$rcpr = new CheckboxField ( 'recv_produktleitung', _t ( 'ContactForm.RECV_PRODUKTLEITUNG', 'produktleitung' ), 1 );
else
$rcpr = new CheckboxField ( 'recv_produktleitung', _t ( 'ContactForm.RECV_PRODUKTLEITUNG', 'produktleitung' ) );
$fields = new FieldSet ( new OptionsetField ( 'geschlecht', 'geschlecht_t', array ('1' => _t ( 'Contactform.MALE', 'Herr' ), '2' => _t ( 'Contactform.FEMALE', 'Frau' ) ) ), new TextField ( 'name', 'Name', '', TEXTFIELD_MAXLENGTH ), new TextField ( 'vorname', 'Vorname', '', TEXTFIELD_MAXLENGTH ), new TextField ( 'strasse', 'Strasse', '', TEXTFIELD_MAXLENGTH ), new TextField ( 'plz', 'PLZ', '', 5 ), new TextField ( 'ort', 'Ort', '', TEXTFIELD_MAXLENGTH ), new EmailField ( 'email', 'E-Mail Adresse', '', TEXTFIELD_MAXLENGTH ), new TextField ( 'telefon', 'Telefon', '', TEXTFIELD_MAXLENGTH ), $rcc, $rcp, $rcb, $rcpr, new TextareaField ( 'message', 'titel', 10, 180, '' ) );
$actions = new FieldSet ( new FormAction ( 'submit', 'Abschicken' ) );
// $requiredFields = new RequiredFields ( 'geschlecht', 'name', 'vorname', 'strasse', 'plz', 'ort', 'email', 'telefon', 'message' );
// $requiredFields = new RequiredFields('name', 'plz');
// parent::__construct ( $controller, $name, $fields, $actions, $requiredFields );
parent::__construct ( $controller, $name, $fields, $actions );
}
function forTemplate() {
return $this->renderWith ( array ($this->class, 'Form' ) );
}
function submit()
{
echo "or here...";
}
}
The HTML-form-Code, that is created looks like this:
<form id="ContactForm_Kontakt" action="/kontakt/Kontakt" method="post" enctype="application/x-www-form-urlencoded">
...
<input class="action" id="ContactForm_Kontakt_action_submit" type="submit" name="action_submit" value="Abschicken" title="Abschicken" />
</form>
As I understand, the method "submit" of my form class should be called, if the form will be transmitted. But this method is never reached. Does anybody know, what's the reason for that?
Thank you,
roelfsche