Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter validations
    text
    copied!<p>I have a set of fields to validate. Here is the scenario.</p> <p>Let's say I have fields shown below. Since the names are the same I put a number and add at the end.</p> <blockquote> <p>job_title_1 company_name_1 responsibilities_1</p> <p>job_title_2 company_name_2 responsibilities_2</p> <p>job_title_3 company_name_3 responsibilities_3</p> </blockquote> <p>In my view, I used (for statement) to loop and assign this number at the end of the field name, then pass the variable “ctr = 3” in my controller.</p> <p>I use validation like this</p> <pre><code> $validation_errors = array(); for ($i = 1; $i &lt;= $ctr; $i++) { $this-&gt;form_validation-&gt;set_rules('career_objectives_' . $i, 'Career objectives title', 'trim|required'); $this-&gt;form_validation-&gt;set_rules('job_title_' . $i, 'Job title / position', 'trim|required'); $this-&gt;form_validation-&gt;set_rules('company_name_' . $i, 'Company', 'trim|required'); $this-&gt;form_validation-&gt;set_rules('from_date_employment_' . $i, 'From date of employment', 'trim|required'); $this-&gt;form_validation-&gt;set_rules('to_date_employment_' . $i, 'To date of employment', 'trim|required'); $this-&gt;form_validation-&gt;set_rules('responsibilities_' . $i, 'Responsibilities type', 'trim|required'); $this-&gt;form_validation-&gt;set_error_delimiters('&lt;div class="valid-err"&gt;', '&lt;/div&gt;'); if ($this-&gt;form_validation-&gt;run() == FALSE) { $validation_errors[$i] = validation_errors(); } } </code></pre> <p>I decided to put the validation_errors in an array so that I could get this in my view and place the string error in a separate location. My problem now is even the job_title_1 only has error. All the job_title from 1 to 3 produced an error. I think validation_errors() was not clear to the next loop.</p> <p>Any help would greatly appreciated.</p> <p>I already posted it in <a href="http://en.wikipedia.org/wiki/EllisLab#CodeIgniter" rel="nofollow noreferrer">CodeIgniter</a> forums but I haven't got the right solutions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload