Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

how can I inject html into a validation message


Go to End


2 Posts   1027 Views

Avatar
Nicolaas

Forum Moderator, 224 Posts

1 June 2016 at 9:33pm

Edited: 01/06/2016 9:33pm

In SS 3.3 it seem impossible to do this:

<?php

class Listing_FrontEndRequiredField extends RequiredFields
{

    //......

    public function php($data)
    {
        $valid = parent::php($data);
        //......
                                $this->validationError(
                                    'A listing with this name already exists, please <a href="'.$otherListing->Link().'">edit existing listing</a>.'
        //......
        //......
    }

    //......

}

Any ideas / hacks I can use to have the link show as a link rather than an escaped link.

Avatar
martimiz

Forum Moderator, 1391 Posts

4 June 2016 at 2:19am

Looks like in Form::Validate() the message is converted. ~#1312

$error['message'] = Convert::raw2xml($error['message']);

If you comment this line, it should work. Note to others reading this: not advisable, but overridable in some safe way I guess :)