5095 Posts in 1518 Topics by 1114 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 924 Views |
-
comment creation in button function

31 October 2009 at 11:56am Last edited: 1 November 2009 1:22am
Hello community,
i hope you can help me with the following problem:
i want to create a button and when you click on this button it should call a function.
So i tried this:
in page.php i added:function showbutton() {
$button = new FormAction (
$action = "doAction",
$title = "Submit button"
);
return $button;
}function doAction() {
my code.....
}in the template i add $showbutton.
when i open the page, i can see the button but nothing happens when i click on it.
Regards,
StarForce -
Re: comment creation in button function

31 October 2009 at 1:52pm
For that to work the button has to be in a form object. You might have to do something like pass a blank field to to get the form to work
function showbutton() {
return new Form($this, 'showbutton', new FieldSet(new HiddenField('Hidden')), new FieldSet(new FormAction('doAction', 'Submit Button')));
} -
Re: comment creation in button function

31 October 2009 at 11:12pm
ah ok, i didn´t know that
thanky you willr
it works now
-
Re: comment creation in button function

1 November 2009 at 1:21am Last edited: 1 November 2009 1:24am
hmm... now i have a new problem
i want to create a comment when i click on the button
when i add this to the do action function and click the button, no comment is beeing created...
$comment = new PageComment();
$comment->Name = "Name";
$comment->Comment = "DasIstDerComment";
$comment->ParentID = "1";
$comment->write();but when i add it to showbutton it works (it creates a comment each time i visit the site) so the code itself should be right?
Thank you
StarForce
-
Re: comment creation in button function

1 November 2009 at 10:41am
Well does it call the doAction function at all? Put a die() in that function to see if it calls it at all.
Actually looking at your code I think it is because doAction() needs 2 parameters (one for the data, one for the form object) so try change the function line to..
function doAction($data, $form) {
... -
Re: comment creation in button function

2 November 2009 at 3:30am
thank you very much for your help
it works now
| 924 Views | ||
|
Page:
1
|
Go to Top |


