Note that there are some explanatory texts on larger screens.

plurals
  1. POCallback Validation
    primarykey
    data
    text
    <p>I am having an issue trying to display the form validation error on the view using a callback validation function. If the user selects 'Yes' for the vehicle option, the form should check for other mandatory fields related to that vehicle option field. </p> <p>In my controller I have a simple function that outputs the form and gets data back from the form:</p> <pre><code>function new_customer_record() { if ($this-&gt;form_validation-&gt;run() == FALSE) { // data array has values to be passed to the customer_form_view $this-&gt;load-&gt;view('customer_form_view',$data); }else{ //get data from the post method and save it to the database } } </code></pre> <p>In the config folder, I have a file called from_validation.php that has the array filled with validation rules and the callback function as shown below:</p> <pre><code>$config = array ( 'employee/new_record' =&gt; array( array ( 'field' =&gt; 'first_name', 'label' =&gt; 'First Name', 'rules' =&gt; 'required', ), array ( 'field' =&gt; 'vehicleOwn', 'label' =&gt; 'Own a vehicle', 'rules' =&gt; 'required|callback_checkVehicleInfo', ), ), ); function checkVehicleInfo($str){ if ($str == "Yes"){ $config = array ( 'employee/new_record' =&gt; array( array ( 'field' =&gt; 'vehicle_model', 'label' =&gt; 'Vehicle Model', 'rules' =&gt; 'required' ), array ( 'field' =&gt; 'vehicle_rego', 'label' =&gt; 'Vehicle Rego', 'rules' =&gt; 'required' ), array ( 'field' =&gt; 'vehicle_type', 'label' =&gt; 'Vehicle Type', 'rules' =&gt; 'required' ), ), ); $this-&gt;form_validation-&gt;set_message('checkVehicleInfo','Please enter your vehicle information'); return FALSE; }else{ return TRUE; } } </code></pre> <p>In the view, i have something similar to this for each field that has 'required' validation rule - other fields work fine except the vehicle mandatory fields (in the callback function):</p> <pre><code>&lt;?php $vehicle_model = @field($this-&gt;validation-&gt;vehicle_model, $customer- &gt;vehicle_model); ?&gt; &lt;tr&gt; &lt;td&gt;&lt;label&gt;Vehicle Model&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="vehicle_model" type="text" value="&lt;?php echo ($edit=== true)? $vehicle_model :set_value('vehicle_model'); ?&gt;" size="20" maxlength="20"&gt; &lt;?php echo form_error('vehicle_model'); ?&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>But I am not getting any error messages displayed, the validations is not working either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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