Reputation: 3277
I have a html form that his action is for "exmaple.com/mail.php?name=dan
" for example.
How can I pass this parameter to Codeigniter's controller?
the 'action' in codeigniter is going to - example.com/mail
, can't I do exmaple.com/mail?name=dan
, right? so what can I do? (And.. I can't use Ajax for this :-))
Upvotes: 1
Views: 5829
Reputation: 1306
There are several solutions. You can do it like this $name=$this->input->get("name")
, but if you want to preserve the Codeigniter's philosophy you can use Javascript to change the action url of the form to /mail/dan. In that case you can access the data with this: $name=$this->uri->segment($number)
. $number in your case is 2, becouse "dan" is in the second URI's segment.
NOTE: If you use the second aproach, keep in mind that codeigniter's default behaviour is to automatically call controller/method from first and second segment of URI. (http://domain.com/controller/method ) In order to prevent this behaviour you can edit application/config/routes.php file. For detailed instructions refer to oficial guide.
Upvotes: 2
Reputation:
Why can't you simply add a hidden field inside that HTML form and send it along with the form as POST data?
<input type="hidden" name="name" value="dan" />
Of course you would replace the value part dynamically with whatever value you currently have.
Upvotes: 0
Reputation: 15390
You should also set querystring variables to true:
In your CodeIgniter config;
$config['enable_query_strings'] = TRUE;
But keep in mind that this changes the way your codeigniter app behaves. See more here
Upvotes: 0
Reputation: 95639
You can emit the GET parameter as a hidden input element, i.e.:
<input type=hidden name="name_of_parameter" value="value_of_parameter" />
HOWEVER, there are two very important things to keep in mind when doing this:
Since I'm inferring from your example that you are using this to identify and authenticate the user, I strongly recommend you use a browser cookie for this (as well as a digital signature that encodes the checksum of this data, so that if it is altered, you can easily identify that it is invalid).
Upvotes: 1