Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can I return params from extended validation rule?
  • Hello.
    I'm creating work table system.
    I wont to check working time conflict by reference to DB.

    ---------------------------------------
    <VIEW>
    ---------------------------------------
    (1) Select Staff.
    <select name="staff">
      <option value="1" selected>Tom</option>
      <option value="2">Angela</option>
      <option value="3">Bob</option>
    </select>

    (2) Input work time range.
    <input type="text" name="work_time_start" value="10:00">
    <input type="text" name="work_time_end" value="12:00">

    (3) Select work day.
    <input type="checkbox" name="mon" checked> Monday
    <input type="checkbox" name="tue" checked> Tuesday
    <input type="checkbox" name="wed"> Wendsday
    <input type="checkbox" name="thu"> Thuesday
    <input type="checkbox" name="fri"> Friday
    <input type="checkbox" name="sat"> Saturday
    <input type="checkbox" name="sun"> Sunday

    ---------------------------------------
    <SQL>
    ---------------------------------------
    SELECT * FROM tbl_work_tables WHERE
    (staff_id = '1') AND
    (work_time_start > '10:00' AND work_time_end < '12:00') AND
    (work_mon = '1' OR work_tue ='1');

    --------------------------------------------------------------------

    When conflict work time, show error in view.
    Then I wont to show which week day is conflict.
    It's like this:
      "[ CONFLICT ! ] Tom cannot work Monday at this time. "

    I think It need to return conflict week day  from validation.
    Like:
    -------------------------------
    <Validation> 
    -------------------------------
    public static function _validation_conflict_check($val...)
    {

     $conflict_weeks = Model_WorkTimes::...->get();
     ...
     return $conflict_weeks;

    }

    mmm....
    What is best way this case?

  • HarroHarro
    Accepted Answer
    You can only return a result from a validation rule:
    - true: validation has passed, validated value is unaltered
    - false: validation has failed, validated value is unaltered
    - other value: will replace the validated value and is considered a pass

    So no, you can not return a value and fail the validation at the same time. You can have your custom validation rule set a custom message from within the rule:

    \Validation::active()->set_message('conflict_check', '[ CONFLICT ! ] Tom cannot work Monday at this time. ');

    Note that validation messages are set by rule, not by field, so this doesn't work if you have multiple fields using the same validation rule, and you want to display unique messages.
  • Thanks a lot, I unserstand:)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion