Reputation: 237
I am trying to target an edit on the standardId property of the DB. For now I am manually typing the ID value into the Input field for standard ID but ideally I will have the property as not visible eventually.
When attempting to edit existing properties in DB I receive the following error:
Type: Argument Count Error
Message: Too few arguments to function Standards::edit(), 0 passed in D:\xamp\htdocs\myisogo\system\core\CodeIgniter.php on line 532 and exactly 1 expected
Filename: D:\xamp\htdocs\myisogo\application\controllers\Standards.php
Line Number: 39
Model:
public function edit_standard()
{
$this->load->helper('url');
$data = array(
'standardid' => $this->input->post('standardId'),
'standardcode' => $this->input->post('standardCode'),
'standardname' => $this->input->post('standardName')
);
return $this->db->insert('isostandard', $data);
}
Controller:
$this->load->helper('form');
$this->load->library('form_validation');
$data['standard'] = $this->standard_model->get_standard_byId($standard_id);
$this->form_validation->set_rules('standardId', 'standardid', 'required');
$this->form_validation->set_rules('standardCode', 'standardcode', 'required');
$this->form_validation->set_rules('standardName', 'standardname', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header');
$this->load->view('templates/navbar');
$this->load->view('standards/edit', $data);
$this->load->view('templates/footer');
}
else
{
$this->standard_model->edit_standard();
$this->load->view('standards/success');
}
View:
<?php echo form_open('standards/edit'); ?>
<h1>Amend Existing standard </h1>
<h2><?php echo $standard['standardId']; ?></h2>
<label for = "title"> Standard ID </label>
<input type="input" name = "standardId"/><br />
<label for="title">Standard Code</label>
<input type="input" name="standardCode" /><br />
<label for="text">Standard Title</label>
<textarea name="standardName"></textarea><br />
<input type="submit" name="submit" value="Create new standard" />
</form>
Upvotes: 0
Views: 4813
Reputation: 1014
I am assuming that your method from Standards::edit is:
public function edit($standard_id)
$this->load->helper('form');
$this->load->library('form_validation');
$data['standard'] = $this->standard_model->get_standard_byId($standard_id);
$this->form_validation->set_rules('standardId', 'standardid', 'required');
$this->form_validation->set_rules('standardCode', 'standardcode', 'required');
$this->form_validation->set_rules('standardName', 'standardname', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header');
$this->load->view('templates/navbar');
$this->load->view('standards/edit', $data);
$this->load->view('templates/footer');
}
else
{
$this->standard_model->edit_standard();
$this->load->view('standards/success');
}
}
In this case $standard_id is always required. Right?
But the problem is your form_open. You are passing an URL without the id.
<?php echo form_open('standards/edit'); ?>
With this, when you submit the form, you'll submit to //localhost/standards/edit
, but COdeIgniter only accepts //localhost/standards/edit/<some_id_here>
.
You have two choices
Do not pass url to form_open, since you are not posting to other endpoint.
<?php echo form_open(); ?>
Edit your form_open and concat the id
<?php echo form_open("standards/edit/{$standard['standardId']}"); ?>
I stick with the first one.
If you want to make a parameter optional you need to assign the default value public function edit($standard_id=null)
Upvotes: 1