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! Quote Link to comment 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. Quote Link to comment 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()" ? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
dwest Posted January 18, 2007 Author Share Posted January 18, 2007 OK. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.