Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#106 2024-02-17 21:26:20
Re: glz_custom_fields v2 beta for Textpattern v4.7
amordecosmos wrote #336693:
Is there a way to extract the pre-entered values of select/multi-select or checkbox/radio button … and display on a public page … without resorting to some <txp:php> database coding?
Not currently. There is a non-public function in the plugin but it requires more input values. If you’re not totally averse to using <txp:php>, you could quite easily do:
<txp:php>
global $variable;
$rs = getThings("
SELECT `value`
FROM
".safe_pfx('custom_fields')."
WHERE
`name` = 'custom_2_set'
ORDER BY id ASC");
$variable['cf_values'] = $rs ? implode(",", $rs) : '';
</txp:php>
replacing the 2 in custom_2_set with the number of the custom field you want and cf_values with the name of the variable you want to use on your page (template).
You’d then use:
<txp:variable name="cf_values" />
to output those values. For now, this just gives you a comma-separated list in the order you input the values, e.g. Sci-Fi,Romance,Thriller,Pre-Code.
If you want to turn that into a select dropdown, you need to use txp:variable with the attribute breakby="," to denote split the list by comma, and then wraptag, break and if desired class and html_id. Use the sort="asc" to alphabetize the sort order. For example to get your select dropdown, you could do:
<txp:variable name="cf_values" breakby="," wraptag="select" break="option" html_id="genre-chooser" />
which gives you:
<select id="genre-chooser">
<option>Sci-Fi</option>
<option>Romance</option>
<option>Thriller</option>
<option>Pre-Code</option>
</select>
TXP Builders – finely-crafted code, design and txp
Offline
#107 2024-02-18 18:14:57
Re: glz_custom_fields v2 beta for Textpattern v4.7
This is a great solution, thank you.
Offline
#108 2024-07-25 14:08:18
Re: glz_custom_fields v2 beta for Textpattern v4.7
—————————————-
Edit: oops I haven’t noticed that there is already a new version that fixes these.
Anyway if you are running an old site that uses v2.0beta and upgrading to PHP 8 then this may be somehow useful to you, but firstly check the new latest version here .
—————————————-
There are 3 code changes:
1. Change this:
// Removes { } from values which are marked as default
function glz_clean_default($value)
{
$pattern = "/^.*\{(.*)\}.*/";
return preg_replace($pattern, "$1", $value);
}
To this:
// Removes { } from values which are marked as default
function glz_clean_default($value)
{
$pattern = "/^.*\{(.*)\}.*/";
return preg_replace($pattern, "$1", $value ?? '');
}
2. Comment out the glz_fButton function like this:
(It seems like we do not need it and it just throwing errors)
/*
function glz_fButton($type, $name, $contents='Submit', $value, $class='', $id='', $title='', $onClick='', $disabled = false)
{
$o = '<button type="'.$type.'" name="'.$name.'"';
$o .= ' value="'.htmlspecialchars($value).'"';
$o .= ($class) ? ' class="'.$class.'"' : '';
$o .= ($id) ? ' id="'.$id.'"' : '';
$o .= ($title) ? ' title="'.$title.'"' : '';
$o .= ($onClick) ? ' onclick="'.$onClick.'"' : '';
$o .= ($disabled) ? ' disabled="disabled"' : '';
$o .= '>';
$o .= $contents;
$o .= '</button>';
return $o;
}
*/
3. Change this:
// Convert to delimited string …
$value = implode($value, '|');
To this:
// Convert to delimited string …
$value = implode('|', $value);
Please let me know if there are any issues with the changes I have made.
Last edited by THE BLUE DRAGON (2024-07-25 14:46:49)
Offline
#109 2024-07-25 14:21:55
Re: glz_custom_fields v2 beta for Textpattern v4.7
Hi Gil, actually they – and a few others – have all been made already in my GitHub repo
and #2 is long gone, which makes me think you might have been using Gerhard’s very old version.
TXP Builders – finely-crafted code, design and txp
Offline
#110 2024-07-25 14:38:07
Re: glz_custom_fields v2 beta for Textpattern v4.7
jakob wrote #337458:
Hi Gil, actually they – and a few others – have all been made already in my GitHub repo
and #2 is long gone, which makes me think you might have been using Gerhard’s very old version.
Oh thank you Julian, good to know, I have been working on an old site that uses v2.0 beta, oops 👴, will check your new version code 👍🙏
Offline
#111 2024-07-27 16:25:56
Re: glz_custom_fields v2 beta for Textpattern v4.7
jakob wrote #337458:
my GitHub repo
Hi, I’m trying to use your new version but I can’t find the new txt installation file, when I visit the dist folder there is only the none fixed glz_custom_fields_v2.0.1_zip.txt file from 3 years ago without the PHP8 fixes.
Offline
#112 2024-07-28 08:52:27
Re: glz_custom_fields v2 beta for Textpattern v4.7
THE BLUE DRAGON wrote #337480:
Hi, I’m trying to use your new version but I can’t find the new txt installation file, when I visit the
distfolder there is only the none fixedglz_custom_fields_v2.0.1_zip.txtfile from 3 years ago without the PHP8 fixes.
Sorry about that. Try glz_custom_fields_v2.0.5_zip.txt. Let me know if it works well for you and I can update the changelog and title post.
Note: It doesn’t yet include the most recent commit with CSP-compatible script and style tags as I’m still tracking down an anomaly that may or may not have to do with this plugin.
TXP Builders – finely-crafted code, design and txp
Offline
#113 2025-05-12 07:10:50
Re: glz_custom_fields v2 beta for Textpattern v4.7
Textpattern 4.9-dev + PHP 8.4.x
glz_custom_fields is at version 2.0.5
The default value for a radio set is wrapped in a { } as suggested on the cf admin /setup pane. However, somewhat unexpectedly on the Write panel the output also includes the { } wrapper.
screen grab for a yes/no radio set.
Bug or misunderstanding on my part? (I don’t think it used to be the case in the past)
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
#114 2025-05-12 07:12:00
Re: glz_custom_fields v2 beta for Textpattern v4.7
Thanks for the report. I’ll check it and see if I can repair that.
TXP Builders – finely-crafted code, design and txp
Offline
#115 2025-05-12 09:02:30
Re: glz_custom_fields v2 beta for Textpattern v4.7
v2.0.6 should fix that. If there are any problems, let me know.
TXP Builders – finely-crafted code, design and txp
Offline
#116 2025-05-13 01:32:38
- GugUser
- Member

- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: glz_custom_fields v2 beta for Textpattern v4.7
Thank you very much Jakob for continuously keeping this important plug-in up to date.
Offline
#117 2025-05-13 01:56:45
Re: glz_custom_fields v2 beta for Textpattern v4.7
jakob wrote #339691:
v2.0.6 should fix that. If there are any problems, let me know.
Yes, both type=radio and select now display nicely. Thanks .
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
#118 2025-05-13 07:28:29
Re: glz_custom_fields v2 beta for Textpattern v4.7
jakob wrote #339691:
v2.0.6 should fix that. If there are any problems, let me know.
I did some more (light) testing and all appear to work as expected – configuring a CF, write panel output, public side usage. Not tested: date and time CF and custom script based CF.
BTW, in the release notes you mentioned:
Some CSP aware inclusion of style and script blocks
With some strict(-ish) CSP on the admin side, this did trigger errors (style-src-elem and script-src-elem blocked as the nonce is not set for the script and style blocks).
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
#119 2025-05-13 13:43:39
Re: glz_custom_fields v2 beta for Textpattern v4.7
Try the updated txt installer on the v2.0.6 release page (with _zip.txt). It looks like I originally compiled from a site installation that for some unknown reason was lacking exactly the salient commit. This time I went back to first principles and compiled using Jukka’s compiler… This also has your css tweaks but doesn’t warrant a new version bump.
TXP Builders – finely-crafted code, design and txp
Offline
#120 2025-05-14 04:39:15
Re: glz_custom_fields v2 beta for Textpattern v4.7
We are nearly there :-)
The CSP nonce is now applied everywhere I think. But. Now I get this error on the plugin admin panel – the list panel with all the CF; the edit panel is fine:
[Error] Refused to execute http://txpdev.test/textpattern/%22index.php?event=glz_custom_fields&step=get_js as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.
(Firefox wording)
The result is that the glz_jqueryui.sortable.min.js script is not applied.
I suspect the clue is in the URL: textpattern/%22index.php. There might be a single " on the loose.
Disabling the header result in a 404 error only (for the URL above)
Failed to load resource: the server responded with a status of 404 (Not Found)
(of course…)
Edit: the loose " is here :
$js_positionsort = glz_inject_js('"index.php?event=glz_custom_fields&step=get_js', 1);
Removing the loose offender fixed the issue.
Last edited by phiw13 (2025-05-14 04:52:39)
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline