Welcome Guest, Not a member yet? Register   Sign In
Stupid Form Error
#1

[eluser]Bionicjoe[/eluser]
I just got back to my first CI project I started a couple of months ago, and I guess I left myself with an error. When I submit my form it is trying to submit the submit button as a field in the db.

I don't remember having this problem when I left off, but I'm stuck. Just getting back into things and I don't have a great grasp of what's going on just yet. Sorry for such a simple question, but my Google searches haven't yielded any help.

Code:
echo form_open('create');
?>
                <table>
                    <tr><td>Number           </td><td>&lt;?php echo form_input('ticketnumber');?&gt;</td></tr>
                    <tr><td>Affected Services</td><td>&lt;?php echo form_dropdown('servicename', $serviceoptions); ?&gt;</td></tr>
                    <tr><td>Summary          </td><td>&lt;?php echo form_input('summary');?&gt;</td></tr>
                    <tr><td>Location         </td><td>&lt;?php echo form_multiselect('sitename', $siteoptions); ?&gt;</td></tr>
                    <tr><td>Start            </td><td>&lt;?php echo form_input('starttime');?&gt;</td></tr>
                    <tr><td>End              </td><td>&lt;?php echo form_input('endtime');?&gt;</td></tr>
                    <tr><td>                 </td><td>&lt;?php echo form_submit('submit', 'Submit');?&gt;</td></tr>
                </table>
&lt;?php

echo form_close();
#2

[eluser]mddd[/eluser]
The form is fine, but the error is probably in the code that handles the input after you submit it.
Sounds you are trying to submit the 'submit' variable.. why??

Maybe you are just taking every $_POST variable and writing that to the database?

That would be bad practice! A user could send any variables the like, so you should always make sure you only store things you WANT to store.
#3

[eluser]Bionicjoe[/eluser]
You're right. This is my controller function.
I think I got confused with several different tuts telling me how things COULD be done. Still haven't fixed it.

Code:
function createoutage()
  {
    $this->load->model('outage_model','',TRUE);
    $this->outage_model->addoutage($_POST);
    redirect('index','refresh');
  }
#4

[eluser]Bionicjoe[/eluser]
Actually the problem was in the View.
I was passing Submit as a field. All I needed to do was remove the name attribute from the Submit button.

&lt;?php echo form_submit('', 'Submit');?&gt;
#5

[eluser]mddd[/eluser]
I don't agree with you there. Sure, taking out the 'name' attribute takes the problem away now.
But it is just bad practice to insert stuff into your database without checking it first!!
You should always take care you only use information that you expect to come from the user.
#6

[eluser]Bionicjoe[/eluser]
If you are talking about validation that's because I haven't gotten that far yet. I just needs something basic that works for a test now.




Theme © iAndrew 2016 - Forum software by © MyBB