No problem, should have thought to do that in the first place.
/** * Update an existing job. * @param int $job_number The number of the job to update. */ public function update($job_number=0) { $this->load->model('Job_model'); $job = array(); $address = array();
// Otherwise, get the data from the database. else { $job = $this->Job_model->search($job_number); $job = $job[0]; $job['datetime'] = new DateTime($job['datetime']); $address = $this->Job_model->get_address($job['joblocation']); $address = $address[0]; }
// Get the street types. $street_types = array(); $this->load->model('staff_model'); $streets = $this->staff_model->get_street_types();
foreach ($streets as $street) { $street_types[$street['streettype']] = $street['streettype']; }
Your form action method needs to include the job number parameter (see snippet above) which the controller method is defaulting to ‘0’ unless you pass it in form_open().
However, that doesn’t explain why the form vars are not in the POST array.
I see that the name of your input field name ‘job_number’, is not the same as the original var name $job[‘job_no’] It doesn’t necessarily need to be the same, but could be confusing.
Good point, and fixed, but as you say, that doesnt explain why POST array is empty. I also changed job_number to be jobno like the variable, but no changes, though I also didnt expect that to change it.
Get array was indeed set to true, I have changed this while noting that it may cause some problems as I dont know if anywhere is using get. I dont think it is, but better safe then sorry.
print_r prints out nothing, but var_dump of the same variable prints out bool(false).
But otherwise, no change, still not updating, and so I assume still no data.
...
print_r prints out nothing, but var_dump of the same variable prints out bool(false).
But otherwise, no change, still not updating, and so I assume still no data.
The boolean false is the correct response from CI’s input class helper, which means it is working but not finding any fields in the post array.
Since the correct controller is being executed, that means the form_open action parameter is working correctly now.
It may not be important, but I think all form input field statements should escape the end carat: ‘>’ rather than just ‘>’. You are coding those by hand, rather than using CI’s helper: “form_input()”, which would automatically escape the end carat ‘>’. The hand coding is fine, I do it myself sometimes, but the escape might be a problem.
ok, so heres an interesting change. I almost always handcode, though I didnt code this page directly myself, that was handled by my team mate, but after putting in those escapes, the print_r($postdata) no longer prints anything out.
Ok, scrap that, I just remembered print_r didnt print anything out, it was var_dump that did.
You could also try putting a print_r($_POST); at the top of your index.php file to see if post is making it through before CI gets ahold of it.
This makes no sense to me, though in the first case that would be because I dont understand how the uri_protocol option affects things.
but the print_r in the index makes no sense, as other pages can handle post data, just not this one and one other for some reason. Especially seeing as how all of this is behind CI’s front door so to speak.
Again, this could be me not understanding how CI does things.
Where exactly are you checking to see if you lost your post data? Early on in your update method, you check if the form was submitted and if it was you redirect just after updating (some) of your data in your model. Redirecting wipes out the POST array (new request to server) so if you’re trying to access it after the redirect you can’t.
Also, you shouldn’t be using $_POST directly, use $this->input->post(‘field’)
not to be rude, but if you read through the code, you would notice that I check the post before the redirect, and that it cant get into the earlier redirect, because post is empty, which means submit is not set. You would also note that I dont use $_POST directly, and that I do use $this->input->post(‘field’);
I only used $_POST for testing if the array was there at all, via var dump
oh, that one instance, my mistake. As I said, this is not my original code, but code I have been tasked with extending. This is, as far as I know, the only time this is used in the controllers, and either way it does not get into there in the first place and is so not the cause of the problem.