editor insert issue

editor insert issue

moonoo1moonoo1 Posts: 11Questions: 6Answers: 0
edited May 2023 in Free community support

I am an editor user.

Receives FULLURL information from editor fields.
(ex: https://www.google.com/search?q=datatable)

In the fullurl information in the save file
I want to save only the baseurl information separately.
(ex:https://www.google.com)

Can I work with the fullurl I entered without requesting an additional baseurl?

fields: [
    {
        "label": "url:", "name": "fullurl",
    }
]
== It's ok ==
$editor->fields(Field::inst('fullurl'));

== here problem!! ==
$editor->fields(Field::inst('baseurl')
            ->setFormatter(function($value, $data) {
            $pattern = '/^(https?:\/\/[^\/]+)/';
            if (preg_match($pattern, $value, $matches)) {
                $baseUrl = $matches[1];
            }
            return $baseUrl 
        }),
);

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    A set formatter is the correct way to do it. Use $data['fullurl'] to get the fullurl value that was suggested from the client-side (rather than $value since you aren't submitting a baseurl).

    Allan

  • moonoo1moonoo1 Posts: 11Questions: 6Answers: 0

    Thanks Allan!

Sign In or Register to comment.