Page 1 of 1
Using a class function to determine a forms action
Posted: Sun Jan 25, 2009 11:31 am
by JoeAckney
Hi, i'm currently trying to learn how to program in PHP using the OO aproach and i'm having trouble with form actions. I'll post the section of code in question and then explain in more detail:
Code: Select all
<form action="$NewPost->buildPost()" method="post">
All relevant files are included and $NewPost is a valid instance of the class buildPost() function belongs to. Currently buildPost() returns a string variable for testing purposes.
Could anyone tell me how i could i use a member function as part of a forms action? Any help would be greatly appreciated!
Thanks,
Martin.
Re: Using a class function to determine a forms action
Posted: Sun Jan 25, 2009 4:54 pm
by requinix
Code: Select all
<form action="$NewPost->buildPost()" method="post">
That's a function, not a variable, so you can't embed it into a string. If you have that as-is right in the HTML, PHP doesn't know it's supposed to do something with it.
Assuming that buildPost() returns a string,
Code: Select all
<form action="<?php echo $NewPost->buildPost(); ?>" method="post">
Re: Using a class function to determine a forms action
Posted: Sun Jan 25, 2009 6:26 pm
by JoeAckney
Sorry, i should have mentioned that ultimately i want it to execute a void function. So rather than run the code in a *.php file (action="buildPost.php") i want it to run the code in a specfic class function ($NewPost->buildPost()) contained within a php file.
I know i could use action="postClass.php?action=buildpost" and have some code outside of the class definition in the same file to call the function, but i was wondering if there was a neater way.
Re: Using a class function to determine a forms action
Posted: Sun Jan 25, 2009 8:54 pm
by John Cartwright
For many good reasons, that is not possible. The not so neat way which you refered is how the rest of us do it.
Re: Using a class function to determine a forms action
Posted: Mon Jan 26, 2009 1:39 pm
by JoeAckney
Okay, I appreciate the replies. I know I'm being far too fussy, after all, if it works then it works
Thanks anyway guys.