|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
dms_90069 Smarty n00b
Joined: 16 Feb 2004 Posts: 3
|
Posted: Mon Feb 16, 2004 3:52 pm Post subject: for actions as function? |
|
|
Greetings,
Firsts thank you for such a great package and resource. I am a newbe and am trying to use a php function as the action for a form. Is that at all possible?
Can you in general bind a php function to the action attribute of a form?
Thanks,
dms[/code] |
|
Back to top |
|
zbert Smarty Rookie
Joined: 11 Dec 2003 Posts: 30 Location: New York
|
Posted: Mon Feb 16, 2004 6:38 pm Post subject: |
|
|
I'm not sure if you can bind a php function to the action attribute of a form but you can suppy key => value pairs. For example;
Code: | <form action="my_account.php?cmd=update" method="post"> |
The action jumps to my_account.php and then evaluates the value of $cmd in a switch statement. So you could put your function and any other code you wish to run inside the switch. I have switches for "add", "delete", etc...
That may give you some ideas.
--zbert |
|
Back to top |
|
dms_90069 Smarty n00b
Joined: 16 Feb 2004 Posts: 3
|
Posted: Tue Feb 17, 2004 4:19 am Post subject: |
|
|
Thanks Zbert,
Is that the prefered way to process forms while using smarty templates? How would you persue the separation of display vs business logic? Are there any references on how to accomplish that with smarty?
Thanks one and all.
dms |
|
Back to top |
|
zbert Smarty Rookie
Joined: 11 Dec 2003 Posts: 30 Location: New York
|
Posted: Tue Feb 17, 2004 4:38 am Post subject: |
|
|
I don't know if that's the preferred way. I've only been trying to learn this myself over the last couple of weeks. I learn a little more each day and I am sure there's a whole lot more to go.
Anyway, I figure you should create your form as a template file (because you can use a nice layout program like Dreamweaver, etc...) and then do all of your processing in a PHP file. Once you've processed your data, you would then create tempalte variables to send back to a Smarty template for display.
--zbert |
|
Back to top |
|
kenzor Smarty Rookie
Joined: 17 Feb 2004 Posts: 9
|
Posted: Tue Feb 17, 2004 4:50 am Post subject: |
|
|
You could always pass the action from PHP to the template...
PHP:
Code: | $smarty->assign('action', 'action.php?function=process'); |
and then in the template:
Code: | <form action="{$action}" method="post"> |
the other option (which i prefer and is much cleaner and safer) is to use hidden input fields:
Code: | <form action="action.php" method="post">
<input type="hidden" name="function" value="process"> |
or yet again another option is to use config variables (but this can just make things confusing and harder to debug) |
|
Back to top |
|
dms_90069 Smarty n00b
Joined: 16 Feb 2004 Posts: 3
|
Posted: Tue Feb 17, 2004 3:56 pm Post subject: |
|
|
Thanks Kenzor,
Your approach looks like the way to go. Although I had mentioned binding the action to a function, what I really wanted was to dynamicly assign the action as in your example.
I will continue to chew on this, but I think I have what I need.
Thanks,
dms |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|