A little PHP help...CodeIgniter Framework.

Status
Not open for further replies.
So I have a HTML table that has rows and columns that get created by a php loop from a database table. Inside one of the columns, I have inserted a textbox so that I user can input a value for that row.
Code:
 <td><input type="text" name="timein[]" id='<?php echo $ID;?>' /></td>

Now, on the post, I need to grab the values for each of the textboxes.
Code:
$timein = $this->input->post('timein');
			
			foreach ($timein as $value) 
			{
				echo $value;
			}

I have tried the above to see if it returns anything and I get this:
Code:
Invalid argument supplied for foreach()

Can anyone help me out here? I'm I approaching this the wrong way?

Thanks!
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
The problem may be a form array of text boxes; I don't know if that's actually handled by PHP (I assume it is, I've just never tried). Assuming it is I think in this case you may have to use $_POST; I don't know if CodeIgniter properly handles HTML form arrays.

Have you tried var_dump()'ing what you get and seeing what type you're actually getting?
 
You should at least use base validation on anything you allow a user to input data into or it's screaming for injection. Something quick like:

Code:
$val = $this->form_validation;

$val->set_rules('someinputname', 'Some Input Name', 'trim|required|xss_clean');

if ($this->form_validation->run() == TRUE)
{
   $someinputname = $val->set_value('someinputname');
   foreach (...) {}
}
 
Blacken00100":35hqns8z said:
The problem may be a form array of text boxes; I don't know if that's actually handled by PHP (I assume it is, I've just never tried). Assuming it is I think in this case you may have to use $_POST; I don't know if CodeIgniter properly handles HTML form arrays.

Have you tried var_dump()'ing what you get and seeing what type you're actually getting?

CodeIgniter does support it. Stupid me had my form tags misplaced.

Blacken00100, I do have to thank you for an early post on one of my other threads where you recommended I use a framework. Switching to CodeIgniter and learning the MVC pattern has proven to be useful beyond my belief. Again, many thanks. It's great to have a cat like you on the block.
 
Blacken00100":312xi2dc said:
I could be wrong (don't quote me on this) but I don't think IDs are passed in via forms at all. It may be a bit hackish, but you might be able to do something along the lines of splitting POST array keys with a delimiter.

I've thought about doing that. How do people normally handle this type of input? I supposed they use AJAX or jquery grids right? Would it be worth it to go that route?
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Canache":2a2j8rm3 said:
Why not keep it simple and just give each textbox an name and ID like 'timein1'...'timeinX'. Then in your submit controller just do a loop? You could loop either on all fields in the POST buffer, or pass the number of text fields in through a hidden field.
You can't just loop based on some numeric value, because it's an expanding (I assume) number of fields. You'd have to trust a JavaScript-populated hidden element to not be lying to you about how many elements there are. I think you'd need to foreach through and inspect IDs directly.
 
Schluppy":d2h6ixty said:
I still need to associate it to the textbox ID

I'm pretty sure you can use your ID as the array index. Like so:

Code:
<input type="text" name="timein[<?php echo $ID;?>]" />

Then your foreach loop would look something like:

Code:
foreach ($timein as $id => $value)
{
    echo $id . ' ' . $value;
}

This worked. Thanks a ton everyone.
 
Status
Not open for further replies.