CodeIgniter Forums
Form validation and array-based form names - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form validation and array-based form names (/showthread.php?tid=45742)



Form validation and array-based form names - El Forum - 10-04-2011

[eluser]Unknown[/eluser]
Hi folks,

This is a question about form validation.

I am dynamically generating a list of existing users from the database so as to enable the admin to change their personal details.

I'm doing so with array-based form names so the code would look like this:

Code:
<label for="username2">Edit Cathy Brown</label>
&lt;input name="usernameEdit[2]" value="Cathy Brown" id="username2" maxlength="30" type="text"&gt;
<label for="email-2">Email:</label>
&lt;input name="emailEdit[2]" value="[email protected]" id="email-2" maxlength="50" type="text"&gt;

The number value, of course, corresponds to the user id in the database table

When I am submitting for form submission I could just check the values like so:

Code:
if(empty(implode($_POST['usernameEdit'])) {

echo "NOT EMPTY";

}

The above uses the implode function to covert the array to a string but what do I need to do so as the set_rules method can handle the input:

Code:
$this->form_validation->set_rules('usernameEdit', 'username','trim|required|max_length[30]');

It is giving me an error message that it is an array not a string