I am using codeiginiter where I have a form like so:
<form action="announcements/submit_announcement" method="post" id="announcement_form">
Where announcements
is my controller.
If I am at www.mysite.com/home and I submit the form it works properly. However, if I am at www.mysite.com/home/ it will append the text above the end, resulting in www.mysite.com/home/announcements/submit_announcement.
It will then get a page not found.
What is going on here? Shouldn't codeiginiter have this in mind and not have this happen? Disappointed in this..
Does anybody have a fix for this?
Just use codeigniter form_open() it makes things so much easier. In application/autoload in helpers include form to load automatically or load in your controller
$this->load->helper('form');
then in your view
echo form_open('announcements/submit_announcement','id="announcement_form"');
Note that I passed your id in there as a string but you can also include a variable for an array, like if you are using bootstrap and want to add a class.
more in the manual: https://codeigniter.com/user_guide/helpers/form_helper.html#form_open note that reading the manual might save you more "disappointment" :-)
Use following instead what you using now
<form action="<?php echo site_url('announcements/submit_announcement');?>" method="post" id="announcement_form">
and now test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.