Welcome Guest, Not a member yet? Register   Sign In
2 submit - 1 form
#1

[eluser]Ivar89[/eluser]
I needed 2 submit buttons for my form, and I think I got it right but whenever I press the second submit button I let i reditrect to a page and give errors and I can't figure out whats wrong with it...
view:
Code:
<?php echo form_open('page/savesection'); ?>
                            <?php foreach ($sections as $section): ?>
                            &lt;input type="radio" name="ID_Section" value="&lt;?php echo $section-&gt;ID_Section ?&gt;">&lt;?php echo $section->strDescription ?&gt;<br />
                            
                            
                            &lt;?php endforeach; ?&gt;<br />
                            &lt;input type="hidden" name="ID_Page" value="&lt;?php echo $ID_Page; ?&gt;" /&gt;
                            &lt;input type="submit" name="save" class="btn" value="Save" /&gt;
                            &lt;input type="submit" name="save" class="btn" value="Add more sections" /&gt;

Controller:
Code:
function savesection()
    {
        
        if($_POST['save'] == 'Save')
        {
            $this->insert_model->Insert_Section_Data($_POST);
            redirect('page');
        }
        else
        {
            $this->insert_model->Insert_Section_Data($_POST);
            redirect('page/addsection');
        }
        return true;
    }

Model:
Code:
function Insert_Section_data($data)
    {
        $data = array('ID_Page' => $data['ID_Page'], 'ID_Section' => $data['ID_Section']);
        $this->db->insert('tblpagesection', $data);
        
        return true;
    }

The else is going wrong.
addsection controller:
Code:
function addsection($id)
    {
        $data['ID_Page'] = $id;
        $this->db->where('ID_Page', $id);
        $data['sections'] = $this->section_model->Get_Section_data($_POST);
        $this->load->view('page/addsection', $data,  FALSE);
    }

when I click the submiot button with Add mor sections it gets me to the right pages but with these errors:
Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for page::addsection()

Filename: controllers/page.php

Line Number: 95

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: id

Filename: controllers/page.php

Line Number: 98

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: id

Filename: controllers/page.php

Line Number: 99

But I don't understand why it doesn't work when I go from page: savesection to addsection(redirect)
but When I just click on menu addsection it DOES work..and I dont get any errors..

any help? or suggestion to do this betterTongue
#2

[eluser]mddd[/eluser]
The reason for your errors is clear: your 'addsection' method needs a variabele: $id. This variable is not passed to it. And because you have redirected, $_POST will be empty. So the call to 'Get_Section_data' will probably not work.

If you need an id after redirecting, you need to
Code:
redirect('page/addsection/'.$_POST['ID_Page']);
or something like that.

By the way, it is not good practice to just put your $_POST variables into a database. You are begging for SQL injection abuse if you do it like that.
#3

[eluser]Ivar89[/eluser]
Thanks,

after I made topic I found out it didn't get the ID_Page but since I am still pretty new at this I did not found out immidiatly how to fixTongue

so thanksBig Grin
and as far as abusing goes; the only one who can abuse it is the admin and he will screw himself with it:o




Theme © iAndrew 2016 - Forum software by © MyBB