dwest Posted January 18, 2007 Share Posted January 18, 2007 Hi to all,If I have a form such as:[code]<form id="form_items" action="" method="post" enctype="multipart/form-data"><input type="submit" name="btn_add_items" value="Add Items" /><input type="submit" name="btn_del_items" value="Delete Selected Items" /><input type="submit" name="btn_add_custom" value="Add Custom Items" /></form>[/code]I want the following conditions to be possible:If "btn_add_items" is selected then post to add_items.phpIf "btn_del_items" is selected then post to del_items.phpIf "btn_add_custom" is selected then post to add_custom_items.phpHow do I code that into the form action?Thanks! Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/ Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 you can write that easily in javascript, but you can achieve the same purpose with php:post to 1 single php file, say process.phpprocess.php:<?phpif ($_POST['submit'] == "Add Items"){ // do this}else if ($_POST['submit'] == "Delete Selected Items"){ // do that,}.. and so on. Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163777 Share on other sites More sharing options...
dwest Posted January 18, 2007 Author Share Posted January 18, 2007 Is there not a way to set a form's action to be a function call? Like action="btn_choice()" ? Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163780 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 of course there is, but it had to be java script. You can not use PHP to run on browser. Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163784 Share on other sites More sharing options...
dwest Posted January 18, 2007 Author Share Posted January 18, 2007 So, if I have a php function in the form page, say, btn_choice(), I can't submit the form to itself and run that function? It HAS to be a javascript function? Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163788 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 you can use something like this for java script:function setFormAction(postTo){ var thisForm = document.getElementById("form_items"); thisForm.action = postTo; return true;}then on each of the button:<input type="submit" name="btn_add_items" value="Add Items" onclick="setFormAction('add_items.php');"/>and so on. Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163793 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 There are many ways to achieve your purpose.java script, like my post above,PHP, like my earlier post.or you can submit to a single PHP file,then insdie this PHP, call function buttonchoice, this function have to include appropriate PHP file. Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163797 Share on other sites More sharing options...
dwest Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks hvle,I understand your PHP code. I don't want to use javascript. I can see that I inadvertently posted in the javascript forum...duh! That caused confusion I'm sure. My apologies.I suppose what I need to know is can I have a php function on this form page that determines what submit button was clicked , and then have the form submit to itself and execute the function? If so, what goes between the quotes in action="" ?Thanks for your patience... Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163806 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 to answer your question, no. PHP can not be embeded inside html to run on browser. Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163808 Share on other sites More sharing options...
dwest Posted January 18, 2007 Author Share Posted January 18, 2007 OK. Thanks! Link to comment https://forums.phpfreaks.com/topic/34749-conditional-form-actionhow/#findComment-163813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.