1

I have the following entry_submission_ready method in an extension to update a field's data. This works fine when saving an entry in the control panel, but it doesn't change the field value on the front end using Channel Form. The function is called, because I can output $data to the screen.

function entry_submission_ready($meta, $data, $autosave)
{
    $data['field_id_281'] = 'Test';

    if(isset($this->EE->api_sc_channel_entries))
    {
        $this->EE->api_sc_channel_entries->data = $data;                
    }
    else
    {
        $this->EE->api_channel_entries->data = $data;
    }
}

It seems $this->EE->api_channel_entries->data is empty on the front end, but is used in the control panel. So what would one use to save the data on the front end using Channel Form?

2

I have got it to work using a second hook, channel_form_submit_entry_start

Using channel_form_submit_entry_start I can manipulate the $_POST array directly, then this saves. Seems wrong I should manipulate $_POST, and also a shame I have to have a second method to do the same as the entry_submission_ready (difficult to combine as I am using different arrays), but at least this works:

function channel_form_submit_entry_start($obj)
{
    $_POST['field_id_281'] = 'Test';
}
1

I don't have experience with the channel form hooks, but I have implemented something similar using the the entry_submission_start hook, which should get fired on an entry submission regardless of whether it comes from the front-end or backend.

You can access and modify the channel data before it gets inserted by accessing $this->EE->api_channel_entries->data by reference.

Something like so would set field_id_281 to have the value of foo regardless of what was submitted in the entry form:

public function entry_submission_start( $channel_id = 0, $autosave = FALSE )
{   
    // access our data by referece
    $this->data =& $this->EE->api_channel_entries->data;
    $this->data['field_id_281'] = 'foo';
}

You'd replace $this->EE with ee() on EE version 2.7+

  • The above example seems to no work with Channel Form EE 2.8.1. The hook method is still called but $this->data won't modify any of the field values. This example however still works in the CP. – Bransin Apr 25 '14 at 3:43
  • 1
    Adding to what is above. Would need to conditionals on whether to use data from frontend or backend. ee()->api_channel_form_channel_entries->data is used for frontend and ee()->api_channel_entries->data is for the backend in EE 2.8 – Bransin Apr 25 '14 at 4:42

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.