I have a plugin that adds a couple extra fields to com_content. I've already sorted out how to add the fields to the frontend editing form, so that they're displayed and saved appropriately, that is working fine for me.

What I'm trying to do is have users fill in one field, and then, when the form is submitted, get the data from that field, manipulate it, and save a variant of that to another field, and have both saved to the database.

For example. A user fills in the video_url field with "https://www.youtube.com/watch?v=uO59tfQ2TbA". When the form is submitted, I get the contents of video_url, manipulate it to isolate the youtube video ID, and then save that to video_id as "uO59tfQ2TbA", and add that to the data saved to the database.

I thought I could use the onContentBeforeSave plugin event, but I think I'm doing something wrong, though, because it's not working lol.

Here's what I've got so far. (to keep the logic simple and figure out how to actually save this second field, I'm currently just copying the first field into the second ... or attempting to.

public function onContentBeforeSave ($context, &$article, &$isNew)

        $app = JFactory::getApplication();
        $option = $app->input->get('option');
        $layout = $app->input->get('layout');

        if($option == 'com_content' && $layout == 'edit') {
            $video_url = $_POST['jform']['attribs']['video_url'];
            $video_id = $video_url;
            $attribs->video_id = $video_id;

            $article->attribs = json_encode($attribs);

Any help? I'm trying to figure this out as I go, haven't done this before.

2 Answers 2


after finding an obscure tutorial with a kind-of-sort-of related intent, I finally sorted out how to do this lol. Here's what I ended up with.

public function onContentBeforeSave($context, $article, $isNew)

        // getting the data from the submitted content
        $attribs = json_decode($article->attribs);

        //logic/code for the process of getting the url, etc. goes here

        // adding my updated field content to the attributes
        $attribs->video_id = $vim_id;

        //Set the new $attribs object for the article
        $article->attribs = json_encode($attribs);

        return true;

that allows me to get information submitted in the form, manipulate it, add to it, change it, etc., and then put it back in right before it is saved to the database.


If I was understanding correctly, was just about to suggest a front-enders solution with a keydown() that records one value from your first field to the second which then uses split().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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