AbanteCart Community

AbanteCart Development => Development Help Needed => Topic started by: yonghan79 on November 12, 2024, 06:06:48 AM

Title: Override or hook into AForm and AHtml
Post by: yonghan79 on November 12, 2024, 06:06:48 AM
Hi, core developers,

i want to ask if it's possible to override AForm and AHtml and then use the overriden as the default one to be used by cart?

I would like to add a custom HTML field that core code can access as well, such as the default contact us form.

Thanks.
Title: Re: Override or hook into AForm and AHtml
Post by: abolabo on November 12, 2024, 10:18:19 AM
What mean custom html field?
Title: Re: Override or hook into AForm and AHtml
Post by: yonghan79 on November 12, 2024, 10:44:06 AM
i mean like custom captcha
Title: Re: Override or hook into AForm and AHtml
Post by: abolabo on November 13, 2024, 06:07:29 AM
Quote from: yonghan79 on November 12, 2024, 10:44:06 AM
i mean like custom captcha

please take a note we added new property for all html-elements of form. it's a "template"
Since v1.4.1 you can set your own tpl file for captcha element inside your controller.

OR...
you can create your own element class and place into your_extension/core directory:

class YourCustomCaptchaHtmlElement extends HtmlElement
{
    public function getHtml()
    {
        $data = [
            'id'       => $this->element_id,
            'name'     => $this->name,
...
        ];

        $this->view->batchAssign($data);
        return $this->view->fetch('form/your_captcha.tpl');
    }
}


Then look at line https://github.com/abantecart/abantecart-src/blob/master/public_html/core/engine/html.php#L899
You custom class will be called from it. Just use correct "type" array key ;-)
P.S. Do not forget include file with your class inside main.php of your extension.

Title: Re: Override or hook into AForm and AHtml
Post by: yonghan79 on November 13, 2024, 11:04:28 AM
How do we allow the custom captcha html element to be available as selection for admin to choose from the field type list? so it is loaded in the contact us form.