21286 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1159 Views |
-
form in page action not submitting

29 August 2009 at 4:57pm
I am trying to create a front-end page editing capability, and set things up so that mysite.com/page/edit would return a (secured) customized page with a form to edit the page content. the problem that i have is that when i hit submit, the page returns to the same url, and nothing gets submitted. I dont know if this is because i am submitting from a url with an action in it or what. here is the code , any help would be appreciated:
class CustomPage_Controller extends Page_Controller{
function EditPage(){//this is called in a url, mysite.com/mypage/EditPage
if(!$this->UserIsAdmin()){
Security::permissionFailure(null);
}
$fields = $this->EditableFields(); // correctly returns fields needed in form
$actions = new FieldSet(
new FormAction('UpdatePage', 'Update')
);
$required = new RequiredFields(
"Title",
"Content"
);
$form = new Form($this, "EditPage", $fields, $actions, $required);
$newdata = array(
'Title' => 'Editing '.$this->Title,
'Content' => '',
'Form' => $form
);
return $this->customise($newdata)->renderWith(array('Page','Page'));
}
function UpdatePage($data, $form){
// ... code here, but this method never gets called...
}
}Thanks alot,
-Chris -
Re: form in page action not submitting

29 August 2009 at 6:46pm
Well it seems that the way you are putting the for in through customise() is causing the form to post back to itself instead of the UpdatePage action.
See the post action in your form as rendered:
<input type="submit" title="Update" value="Update" name="action_UpdatePage" id="Form_EditPage_action_UpdatePage" class="action"/>
It sees EditPage as the form it should be calling to rebuild it and apply the data. Since your function doesn't return a Form object it just re-renders the page when it gets to the renderWith() call.
You can:
1. Move your form creation to a separate function EditPageForm and call it as a $EditPageForm in CustomPage_EditPage.ss template.
2. Add the following arg to your existing code:function EditPage($data){
The $data object will have all your posted data in the ->postVars array.1 is the intended SS way, 2 is the QnD way. Do as you will
-
Re: form in page action not submitting

4 September 2009 at 7:00am
thanks alot dalesaurus, that helped. i ended up using the template and it worked out pretty well. thanks again,
-chris
| 1159 Views | ||
|
Page:
1
|
Go to Top |


