Im developing am mcv framework in php and currently my url format is:
/admin/users/?action=add&method=admin
this will call the ADMIN controller, then call the user function in the admin contoller. The user function loads the admin_model model and the action=add&method=admin will call the add_admin() function.
If your still following, in each model, i have functions such as:
add_admin()
edit_admin()
view_admin()
add_agent()
edit_agent()
etc, etc, etc…
now the add_admin() function returns a html form that the user fills in and submits
on submit, i would like to call a function post_admin()
So my url should be:
/admin/users/?action=post&method=admin
however, I CANT set the action of the html form to that url.
so I need the form to method=”post” the form data and method=”get” the query string
Any Ideas?
I’d be inclined to avoid doing this if I were you, you could just get really confused. Besides, whilst it’s not written in stone, it’s generally considered to use GET for actions that don’t cause changes, and actions that do cause changes should be restricted to POST.
Option 1: Use $_REQUEST
$_REQUEST holds an aggregate of $_GET, $_POST and $_COOKIE (and maybe $_SERVER too, can’t remember for sure).
I’d STRONGLY recommend against using $_REQUEST though, you have no way of knowing if your values came from $_GET or $_POST, and if you have the same variable in both, one will overwrite the other.
The other option is to put the GET part of the request in the form action.
This is better cos you know where the variables come from, but it can get somewhat messy, especially if there’s a lot of data that needs to be sent via GET.
Personally, I’d say your best bet is to just try avoiding mixed submission types altogether and just try to stick to GET or POST.