2

In our system, entries are created from the Control Panel, and one of our custom entries needs more complicated validation rules.

Basically, depending on the status of the submitted entry, we need to determine whether other fields are required, validate the submission based on that and then show errors as per normal validation rules.

I've looked into getting access to the data from the entry_submission_ready hook and setting the errors via ee()->form_validation->_error_array['foo'] = 'bar', but this hook is called after validation has already completed and passed.

Ideally I would prefer not having to rewrite any core code, though I am willing to override Content_publish if this can be done cleanly from a module/extension.

3

You're using the wrong hook. Try using entry_submission_start and/or publish_form_entry_data

Update:

  • 1
    Thanks Peter. Based on what I can see, entry_submission_start is called after validation in Content_publish, and is only passed $channel_id. publish_form_entry_data looks promising though, I'll look into it when I next get a chance. – user2128 Oct 2 '13 at 13:50
  • It is 'technically', but not before the entry is saved, so still time to validate and abort if need be. Added to links for references. – Peter Lewis Oct 2 '13 at 21:03
  • 2
    Definitely the way to go. Solution is to implement the entry_submission_start hook, source the unprocessed submission data from ee()->api_channel_entries->data and add errors to ee()->api_channel_entries->errors using the element name / field name as the key. Errors are then associated correctly with the form elements, and everything looks nice. Thanks! – user2128 Oct 8 '13 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.