I'm new in codeigniter and I've already seen some similar types of questions here. But none worked in my case. I've a form in my view and I've passed the input value from this form to a method named "Insert" inside the controller. Now,I'm trying to move this value from "insert" method "to another method named "post_action". But couldn't make it possible.
This is the Controller:
public function insert() {
$data['values'] = $this->Final_model->insert();
$this->load->view('info/insert',$data);
$val = $this->input->post('coursecode');
echo $val;
$this->post_action($val); //passing data into another function
}
public function post_action($val='')
{
$temp1 = $this->input->post('textbox');
if($temp1== "")
{
$message = "You can't send empty text";
}
else
{
print_r($val);
if($val == NULL) echo 'Value is null bro...';
$grades = $_POST['grade'];
$msg = $_POST['my'];
$message = $_POST['textbox'];
$this->Final_model->build_post($msg,$val,$message,$grades);
echo "Value added successfully";
}
}
This is my 'index' view :
<?php echo form_open('Home_Controller/insert'); ?>
<div class="form-group">
<label>Course Code</label>
<input type="text" class="form-control" name = "coursecode"
placeholder="Add Course Code">
<br> <br>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
This is my 'insert' view :
<?php echo form_open('Home_controller/post_action'); ?>
<td> <input type="text" name="textbox" id = "textbox"> </td>
<td><input type="text" name="grade" id = "grade1"></td>
<input type="hidden" name = "my" value = "<?php echo $value['id']; ?>"
id
= "my"/>
<td><input type="submit" value="Submit"></td>
</form>
Now, it is echoing the correct value in the insert method passed by the view. But in the post_action method, it is echoing "value is null bro" and a 0 is passing to the database table(this one is an insert operation done in the model).
My question is,why can't I get the input value passed from the view, in this post_action method.
P.S: I've already spent about 2 days in this problem but haven't got anything. So, please forgive me if the question is too naive. Thanks in advance.