1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1531 Views |
-
problem with form templating [SOLVED]

28 December 2008 at 7:58am Last edited: 28 December 2008 12:12pm
Hi all,
My problem is in form customizing, here's what I'm trying to do:
code/MyPage.php
class MyPage extends Page {
...
}class MyPage_Controller extends Page_Controller {
function init() {
parent::init();
Requirements::javascript("mysite/javascript/jquery-1.2.6.min.js");
Requirements::javascript("mysite/javascript/order.js");
}function DoOrder() {
$fields = new FieldSet(
new TextField(
$name = "name",
$title = "title",
$value = "asd"
)
);
$actions = new FieldSet(new FormAction("send", "Send"));
$required = new RequiredFields("name");
$form = new Form($this, "DoOrder", $fields, $actions, $required);//here I tried two ways to achieve the form being skinned, but all of them gave me same error (will be listed below)
//first way
// $form = $this->customise($form)->renderWith('MyTemplate');
// return $form;
//second way
// $form = $form->renderWith('MyTemplate');
// return $form;
//well, last way - no template at all and only in this case form and form submission is working
return $form;
}function send($data, $form ) {
print_r($form);
}
}templates/MyPage.ss
$Content
$DoOrdertemplates/includes/MyTemplate.ss
// here is my template for form, meaningless to write it here
Well, it's look all good, and it's even work and actually apply a template to form in first two cases (commented in code) and then render it to browser, but upno form submission an error acquires:
Fatal error: Call to a member function loadDataFrom() on a non-object in C:\Server\httpd\web\sapphire\core\control\Controller.php on line 178
Is there any other ways to customize form without errors? Or maybe my way to do this is good but not complete?
-
Re: problem with form templating [SOLVED]

28 December 2008 at 8:03am
Forgot to say - I need to skin exactly a form object, not page object, so templating directly in MyPage.ss isn't good for me, because for example "<% control Fields %>" will be unavailable in this case.
-
Re: problem with form templating [SOLVED]

28 December 2008 at 12:09pm Last edited: 28 December 2008 12:11pm
[SOLVED]
I found solution, maybe it's not very good, but it's working:
code/MyPage.php
class MyPage extends Page {
...
}class MyPage_Controller extends Page_Controller {
function init() {
parent::init();
Requirements::javascript("mysite/javascript/jquery-1.2.6.min.js");
Requirements::javascript("mysite/javascript/order.js");
}function DoOrder() {
$fields = new FieldSet(
new TextField(
$name = "name",
$title = "title",
$value = "asd"
)
);
$actions = new FieldSet(new FormAction("send", "Send"));
$required = new RequiredFields("name");
$form = new MyForm($this, "DoOrder", $fields, $actions, $required);
return $form;
}function send($data, $form ) {
print_r($form);
}
}class MyForm extends Form {
function forTemplate() {
return $this->renderWith("MyForm");
}
}And two templates, first that just initialize DoOrder, and second that skin a form. Thats it. Working great, without any errors. Maybe it'll be useful for somebody, who faced this problem too...
| 1531 Views | ||
|
Page:
1
|
Go to Top |

