A. The comment form can have required fields through the spamblock plugin. Any chance to check from a comments.tpl whether any of the fields are set to be required? (Something like "if field is required, emit foo bar"?)
B. The contact form can have required fields as well. First of all: Have I gone blind overnight or are those only possible in the dynamic contact form? And second, same question here: Is it possible to check from plugin_contactform.tpl whether a field is required?
YL
Required input fields
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Required input fields
Hi!
A.
Hm, your templates config.inc.php could fetch the configuration value from the plugin and pass it along to the smarty template:
B.
Also presets have required fields:
Required fields can easily be detected inside the template file like
Regards,
Garvin
A.
Hm, your templates config.inc.php could fetch the configuration value from the plugin and pass it along to the smarty template:
Code: Select all
PHP:
$required_fieldlist = serendipity_db_query("SELECT value FROM {$serendipity['dbPrefix']}config WHERE name LIKE '%spamblock%required_fields'", true, 'assoc');
$required_fields = explode(', $required_fieldlist['value']);
$smarty_required_fields = array();
foreach($required_fields AS $required_field) {
$required_field = trim($required_field);
if (empty($required_field)) continue;
$smarty_required_fields[$required_field] = $required_field;
}
$serendipity['smarty']->assign('required_fields', $smarty_required_fields);
TPL:
{if $required_fields.author}Author wird benötigt!{/if}
Also presets have required fields:
Code: Select all
switch ($dynamic_tpl) {
case 'small_biz':
$fields = 'require;'.PLUGIN_CONTACTFORM_FNAME.';text:require;'.PLUGIN_CONTACTFORM_LNAME.';text:'.'require;'.EMAIL.';text:'
break;
case 'detailed':
$fields = 'require;'.PLUGIN_CONTACTFORM_FNAME.';text:require;'.PLUGIN_CONTACTFORM_LNAME.';text:'.'require;'.EMAIL.';text:'
break;
default:
$fields = $this->get_config('dynamic_fields','require;'.NAME.';text:'.'require;'.EMAIL.';text:'.'require;'.HOMEPAGE.';text
break;
}
Code: Select all
{if $field.required}The field {$field.id} is required...{/if}
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: Required input fields
Whoa, that's a lot of code ...
Thanks, I'll check it out over the weekend and report back!
YL
Thanks, I'll check it out over the weekend and report back!
YL
Re: Required input fields
Code for A is working great (but it's name, not author, in that example, and a typo at the explode: ',', instead of ',). Tanks for the answer Garvin, thanks for the question yellowled.
Re: Required input fields
But those only work in the dynamic contact form, right?garvinhicking wrote:B.
Also presets have required fields:
YL
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Required input fields
plugin_contactform.tpl is used only when using the contact form type of "standard" and is essentially the same as the comment form... so I suspect Garvin's method A should work there... whether or not a field is required is determined by the spamblock plugin (I think).
plugin_dynamicform.tpl (or any derivatives of it) is used to handle everything else except "standard" - which includes the presets small business, detailed, and custom. Small business (first name, last name, email, message) and "detailed" (first name, last name, email, mailing address, message) are hard coded as required in the plugin.
"custom" defaults to name (a single field, not first and last), email, homepage, and message and all fields are required. These, as you know, are the ones that can be changed, added to, etc...
So method "B" does not require anything in config.inc.php.. it is in fact, already in use to show superscripted asterisks for required fields in the default plugin_dynamicform.tpl:
So, for comments or the standard contact form, use method A (config.inc.php).... for all other contact form types, use method B.
You definitely do NOT want to require the field "replyTo" since this does not exist in the contact form.. well, not the default contact form anyway.
I'm in the middle of something else today, but when I get a bit of free time, I'll also try playing around with this.
plugin_dynamicform.tpl (or any derivatives of it) is used to handle everything else except "standard" - which includes the presets small business, detailed, and custom. Small business (first name, last name, email, message) and "detailed" (first name, last name, email, mailing address, message) are hard coded as required in the plugin.
"custom" defaults to name (a single field, not first and last), email, homepage, and message and all fields are required. These, as you know, are the ones that can be changed, added to, etc...
So method "B" does not require anything in config.inc.php.. it is in fact, already in use to show superscripted asterisks for required fields in the default plugin_dynamicform.tpl:
Code: Select all
{if $field.required}<sup>*</sup>{/if}
You definitely do NOT want to require the field "replyTo" since this does not exist in the contact form.. well, not the default contact form anyway.
I'm in the middle of something else today, but when I get a bit of free time, I'll also try playing around with this.
=Don=
Re: Required input fields
So now I have an actual use case for this.
This line:
seems to have a type, is it supposed to be ('', maybe?
Also: How do I get the proper field names for the tpl? Your code says author – the spamblock plugin lists name, email, url, replyTo and comment …
YL
This line:
Code: Select all
$required_fields = explode(', $required_fieldlist['value']);
Also: How do I get the proper field names for the tpl? Your code says author – the spamblock plugin lists name, email, url, replyTo and comment …
YL
Re: Required input fields
Figured it out. Call me PHP hacker!
The code line is supposed to be:
because the values are comma seperated in the db. And the field names are the same used by the spamblock plugin: name, email, url, replyTo (you probably don't want to use that as Don pointed out) and comment. Awesome.
YL
The code line is supposed to be:
Code: Select all
$required_fields = explode(',', $required_fieldlist['value']);
YL