A field type to generate a (pseudo-)random string in PerchCMS.
Use this as a supplement to/replacement for the Perch-native slug
field type, if you need a randomly generated slug, for instance.
- Download zip archive and extract locally.
- Create a
frwssr_randomstring
folder in the/perch/addons/fieldtypes/
folder of your perch install. - Copy the file
frwssr_randomstring.class.php
to the/perch/addons/fieldtypes/frwssr_randomstring
folder.
In a perch template, you can use this field type as follows:
<perch:content id="random" type="frwssr_randomstring">
- style - Choose between
alphabetic
,numeric
, andalphanumeric
characters. Defaults toalphanumeric
. - case - Determin whether
lowercase
oruppercase
letters should be used—or if they should bemixed
. This only comes into effect, when thestyle
attribute is set toalphabetic
oralphanumeric
—or is omitted altogether. Defaults tomixed
. - length - Set the desired string length. Defaults to
8
. - prefix - Define a string to be prepended to your randomly generated strings.
- postfix - Define a string to be appended to your randomly generated strings.
- editable - In case you need the field to be editable, just add this boolean attribute—no value required. Be careful with this one, though. You don’t want to break URLs, that are making use of your random strings, or something.
<perch:content id="random" type="frwssr_randomstring" style="alpha" case="mixed" length="11" label="A random string">
- By default the fieldtype is
readonly
to prevent users from accidentally changing the value. - This fieldtype was developed under Perch (Standard) Version 3.1.7 on a server running PHP 7.4.x.
Use at own risk!
This project is free, open source, and GPL friendly. You can use it for commercial projects, for open source projects, or for almost whatever you want, really.
This is free software, but it took some time to develop. If you use it, please let me know—I live off of positive feedback…and chocolate. If you appreciate the fieldtype and use it regularly, feel free to buy me some sweets.
Create a GitHub Issue: https://github.com/frwssr/frwssr_randomstring/issues or better yet become a contributor.
Developer: Nils Mielke ([email protected], @nilsmielke) of FEUERWASSER (@frwssr)