How to send an identifier from a view to Controller CodeIgniter via form_open_multipart

I am trying to send an identifier from a view to a controller in CodeIgniter. My requirement is to switch functions based on the id button. Here is my HTML code.

HTML view

 <?php echo form_open_multipart('upload_control/switch_load','id="bt_addImage"');?>
 <input id= "bt_addImage" type="submit" value="Add Image" /> <br>
 <?php echo form_open_multipart('upload_control/switch_load','id="bt_chooseImage"');?>
 <input type="submit" id="bt_chooseImage" value="Submit"/><br>

Upload_control.php Code

public function switch_load($id)
{
    if($id == "bt_addImage")
    {
        do_loadcategories();
    }
    else
    {
        do_upload();
    }
}
public function do_loadcategories()
{
    //code list categories
}
public function do_upload()
{
    //code to upload
}

Is it correct?

or

is there any other way to do this?

help me solve the problem.

+4
source share
2 answers

In view

$hiddenFields = array('id' => 'bt_addImage'); # add Hidden parameters like this
echo form_open_multipart('upload_control/switch_load', '', $hiddenFields);

In the controller

public function switch_load()
{
    $id = $this->input->post('id');
    if($id == "bt_addImage")
    {
        do_loadcategories();
    }
    else
    {
        do_upload();
    }
}

the view is as follows

<form method="post" accept-charset="utf-8" action="http:/example.com/index.php/upload_control/switch_load">
<input type="hidden" name="id" value="bt_addImage" /> # hidden filed.

Codeigniter Form Helper

+1
source

Change

if($id == "bt_addImage")

IN

if($this->input->post('id') == "bt_addImage")
0
source

Source: https://habr.com/ru/post/1621870/


All Articles