Dynamic Form Action - Determine Action With Variables
I have a form in CodeIgniter, and I need to change the Action of the form based on what is in the actual form.
ie: if <select name="type"> == business
then I need action="business/submit"
Is there a simple way to do this?
Right now my attempted workaround is to use Javascript to grab the data from the inputs, then send it to a dynamically generated link - however it's not ideal for开发者_开发技巧 my situation.
Thoughts?
I have never worked on CodeIgniter but I can tell you how you can do it in PHP.
You have to understand that you cannot do this "dynamically" without Javascript. As you suggested that you do not wish to use Javascript, I am suggesting a dirty way to handle this situation.
You cannot modify the action attribute with PHP alone, so we will have to post it to one PHP file and then based on the selection (from your select box) you can include the file that you need. You can use switch case or if based on your preference.
This is just indicative. Please do not flame me for not following standards or not taking any security measures !
<?php
// sample code snippet
if($_POST['type']=== 'something') {
include 'something.php';
}
else if($_POST['type']=== 'somethingElse') {
include 'somethingElse.php';
}
else {
include 'totallyDifferentOne.php';
}
// continue your code
?>
I'm not familiar with CodeIgnitor, but can't you send the form to a single Action that would read the type
and forward the request to whichever Action you want it to go to?
精彩评论