0

I am taking my fields name as associative array in html code in CodeIgniter but am running into trouble when I validate it.

Here is the code I'm using:

View Page

{<input type="text" name="name[name]">
<?php echo form_error('name[name]'); ?>}

Controller

{$this->form_validation->set_rules('name[name]','name','required');}

How might I solve this?

4
  • Please edit your question and use appropriate tags to format code. Commented Jun 5, 2016 at 20:10
  • Use this article for help. Commented Jun 5, 2016 at 20:16
  • Could you include the error or other information on what happens in the controller? What specifically is the problem you are having? Commented Jun 5, 2016 at 20:20
  • <input type="text" name="name[name]"> <?php echo form_error('name[name]'); ?><input type="text" name="name[name]"> <?php echo form_error('name[age]'); ?> i want validate them using form_validation(); Commented Jun 6, 2016 at 9:42

1 Answer 1

0

you don't repeat the name inside the brackets, they are kept empty like:

   <input type="text" name="name[]">
    <?php echo form_error('name[]'); ?>

Validation

    $this->form_validation->set_rules('name[]','name','required');

note you only would do this if the form field 'name' is occurring more then once in the form.

Sign up to request clarification or add additional context in comments.

2 Comments

actually i am doing same work in core php and its working great, you can see "view-source:kickstarter.com/signup?ref=nav" text box names
i think kickstarter is using ruby and javascript. if you want to use codeigniter then suggest you work through the tutorial in the codeigniter manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.