CodeIgniter Forums
Form-Action Variables not working while routing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Form-Action Variables not working while routing (/thread-77787.html)



Form-Action Variables not working while routing - MarcoElias - 10-19-2020

Hi everyone,
it looks like my CI4 does not process form variables.

I have a very simple form with an action to "/login/" for example.

goes like this:
helper(['form', 'url']);
echo form_open('/login/user_login_process/');
echo form_input("eingabezeile", "eingabezeile");
echo form_close();

If I push the form button, the form fields are not available in the action-controller.
In my action-controller it allways says:
echo $_SERVER['REQUEST_METHOD']; --> "get".
And none of these work: $variable = $this->request->getPost("formfieldname"); doesnt give the value I entered.

I dont see the forest in front of the trees, as we say in german...

Thanks for a tip!
ME.


RE: Form-Action Variables not working while routing - mlurie - 10-19-2020

You need to add your form submit button before form_close()

PHP Code:
echo form_open('/action_route');
echo 
form_input('input_name''input_value');
echo 
form_submit('submit_name''submit_value');
echo 
form_close(); 



RE: Form-Action Variables not working while routing - T.O.M. - 10-20-2020

You must set `method="post"` in your form.
If it is not set, then form sends data with GET.
And you are trying to get data from POST - $this->request->getPost("formfieldname")


RE: Form-Action Variables not working while routing - MarcoElias - 10-20-2020

It now works, probably one of those two things was not correct.
Thank you for your immediate support!!!
ME


RE: Form-Action Variables not working while routing - mlurie - 10-21-2020

(10-20-2020, 01:55 AM)T.O.M. Wrote: You must set `method="post"` in your form.
If it is not set, then form sends data with GET.
And you are trying to get data from POST - $this->request->getPost("formfieldname")

form_open() appears to default to POST according to the documentation: https://codeigniter.com/user_guide/helpers/form_helper.html?#form_open.