Permalink
Browse files

Added built-in support for required fields in comment and (standard) …

…contact forms.
  • Loading branch information...
1 parent 22800cd commit 13a4f305a75ed87f784356a40ca3540f62056f2e @yellowled committed Jan 27, 2012
Showing with 18 additions and 8 deletions.
  1. +4 −4 commentform.tpl
  2. +10 −0 config.inc.php
  3. +4 −4 plugin_contactform.tpl
View
@@ -9,19 +9,19 @@
</div>
<div class="form_field">
<label for="serendipity_commentform_name">{$CONST.NAME}</label>
- <input id="serendipity_commentform_name" name="serendipity[name]" type="text" value="{$commentform_name}" placeholder="{$CONST.TWOK11_PLACE_NAME}"/>
+ <input id="serendipity_commentform_name" name="serendipity[name]" type="text" value="{$commentform_name}" placeholder="{$CONST.TWOK11_PLACE_NAME}"{if $required_fields.name} required{/if}/>
</div>
<div class="form_field">
<label for="serendipity_commentform_email">{$CONST.EMAIL}</label>
- <input id="serendipity_commentform_email" name="serendipity[email]" type="email" value="{$commentform_email}" placeholder="{$CONST.TWOK11_PLACE_MAIL}"/>
+ <input id="serendipity_commentform_email" name="serendipity[email]" type="email" value="{$commentform_email}" placeholder="{$CONST.TWOK11_PLACE_MAIL}"{if $required_fields.email} required{/if}/>
</div>
<div class="form_field">
<label for="serendipity_commentform_url">{$CONST.HOMEPAGE}</label>
- <input id="serendipity_commentform_url" name="serendipity[url]" type="url" value="{$commentform_url}" placeholder="{$CONST.TWOK11_PLACE_URL}"/>
+ <input id="serendipity_commentform_url" name="serendipity[url]" type="url" value="{$commentform_url}" placeholder="{$CONST.TWOK11_PLACE_URL}"{if $required_fields.url} required{/if}/>
</div>
<div class="form_tarea">
<label for="serendipity_commentform_comment">{$CONST.COMMENT}</label>
- <textarea id="serendipity_commentform_comment" name="serendipity[comment]" rows="10" placeholder="{$CONST.TWOK11_PLACE_MESSAGE}">{$commentform_data}</textarea>
+ <textarea id="serendipity_commentform_comment" name="serendipity[comment]" rows="10" placeholder="{$CONST.TWOK11_PLACE_MESSAGE}"{if $required_fields.comment} required{/if}>{$commentform_data}</textarea>
</div>
{serendipity_hookPlugin hook="frontend_comment" data=$commentform_entry}
{if $is_commentform_showToolbar}
View
@@ -9,6 +9,16 @@
function serendipity_smarty_html5time($timestamp) { return date("c", $timestamp); }
$serendipity['smarty']->register_modifier('serendipity_smarty_html5time', 'serendipity_smarty_html5time');
+$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);
+
$template_config = array(
array(
'var' => 'date_format',
@@ -25,22 +25,22 @@
</div>
<div class="form_field">
<label for="serendipity_commentform_name">{$CONST.NAME}</label>
- <input id="serendipity_commentform_name" name="serendipity[name]" type="text" value="{$commentform_name}" placeholder="{$CONST.TWOK11_PLACE_NAME}"/>
+ <input id="serendipity_commentform_name" name="serendipity[name]" type="text" value="{$commentform_name}" placeholder="{$CONST.TWOK11_PLACE_NAME}"{if $required_fields.name} required{/if}/>
</div>
<div class="form_field">
<label for="serendipity_commentform_email">{$CONST.EMAIL}</label>
- <input id="serendipity_commentform_email" name="serendipity[email]" type="email" value="{$commentform_email}" placeholder="{$CONST.TWOK11_PLACE_MAIL}"/>
+ <input id="serendipity_commentform_email" name="serendipity[email]" type="email" value="{$commentform_email}" placeholder="{$CONST.TWOK11_PLACE_MAIL}"{if $required_fields.email} required{/if}/>
</div>
<div class="form_field">
<label for="serendipity_commentform_url">{$CONST.HOMEPAGE}</label>
- <input id="serendipity_commentform_url" name="serendipity[url]" type="url" value="{$commentform_url}" placeholder="{$CONST.TWOK11_PLACE_URL}"/>
+ <input id="serendipity_commentform_url" name="serendipity[url]" type="url" value="{$commentform_url}" placeholder="{$CONST.TWOK11_PLACE_URL}"{if $required_fields.url} required{/if}/>
</div>
<div class="form_tarea">
<label for="serendipity_commentform_comment">{$plugin_contactform_message}</label>
- <textarea id="serendipity_commentform_comment" name="serendipity[comment]" rows="10" placeholder="{$CONST.TWOK11_PLACE_MESSAGE}">{$commentform_data}</textarea>
+ <textarea id="serendipity_commentform_comment" name="serendipity[comment]" rows="10" placeholder="{$CONST.TWOK11_PLACE_MESSAGE}"{if $required_fields.comment} required{/if}>{$commentform_data}</textarea>
</div>
{serendipity_hookPlugin hook="frontend_comment" data=$commentform_entry}
<input id="serendipity_submit" name="serendipity[submit]" type="submit" value="{$CONST.TWOK11_SEND_MAIL}"/>

0 comments on commit 13a4f30

Please sign in to comment.