Reputation: 61
I have a problem where I need to submit or redirect to the page of the same uri.
The main issue here is the url of the id was not read or was not get, How can I get it to insert to my data.
After I submit the page there is an error
An uncaught Exception was encountered
Type: ArgumentCountError
for example my URL is: http://localhost/project/groups/view_activity/1
then I need to submit it to the controller /posts/create_activity
Here is the Controller /posts/create_activity
public function create_activity($id){
$this->post_model->create_activity();
redirect('groups/view_activity/'.$id);
}
And my Model, which I expect that the $id is the URI
public function create_activity($id){
// Insert questions
$field_question = array(
'question'=>$this->input->post('question'),
'group_id' => $id
);
$this->db->insert('questions', $field_question);
}
Form submission
<form method="post" action="<?php echo base_url(); ?>posts/create_activity">
<div class="form-group">
<label for="exampleFormControlTextarea1"><h5> Question: </h5></label>
<textarea class="form-control" name="question" id="question" rows="8" placeholder="Enter your Question"></textarea>
</div>
<hr>
<input type="submit" id="btnSave" class="btn btn-block btn-info" value="Submit" />
</form>
Upvotes: 1
Views: 223
Reputation: 1191
Pass the Id into model function
$this->post_model->create_activity($id);
Upvotes: 0
Reputation: 541
You have to pass $id
from your view_activity
controller method to your view or you can directly get it from uri
in your view.
After that change yourform
action
to
<form method="post" action="<?php echo base_url('posts/create_activity/'.$id); ?>">
.
Alternatively if you do not want it in your uri
you can add one hidden input
with the value of $id
.
Upvotes: 1