Last active
May 4, 2017 03:31
-
-
Save ChrisCree/7208775 to your computer and use it in GitHub Desktop.
Customizing the Genesis HTML5 Comment areas to put labels inside entry fields and have them automatically clear when curser selects the fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function() { | |
jQuery.fn.cleardefault = function() { | |
return this.focus(function() { | |
if( this.value == this.defaultValue ) { | |
this.value = ""; | |
} | |
}).blur(function() { | |
if( !this.value.length ) { | |
this.value = this.defaultValue; | |
} | |
}); | |
}; | |
jQuery(".clearit input, .clearit textarea").cleardefault(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't copy opening php tag | |
// Add support for clearing form default values | |
add_action( 'get_header', 'wsm_add_form_clear_script' ); | |
function sc_add_gform_scripts() { | |
wsm_add_form_clear_script( 'inputfileds', CHILD_URL . '/lib/js/clear_form_fields.js', array( 'jquery' ), '1.0', TRUE ); | |
} | |
/* Note: You're going to want to add CSS to hide the comment form labels too, like this: | |
* | |
* .comment-respond .clearit label { | |
* display: none; | |
* } | |
* | |
*/ | |
// Set the Comment Form Defaults | |
add_filter( 'comment_form_defaults', 'wsm_comment_form_defaults' ); | |
function wsm_comment_form_defaults( $fields ) { | |
$fields['comment_notes_before'] = ''; //Removes Email Privacy Notice | |
$fields['title_reply'] = __( 'Share Your Comments & Feedback:', 'wsm' ); //Changes The Form Headline | |
$fields['comment_field'] = '<p class="clearit comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" tabindex="4">' . __( 'Comment', 'wsm' ) . '</textarea></p>'; // Adds clearit class and default value to comment text area | |
$fields['label_submit'] = __( 'Share My Comment', 'wsm' ); //Changes The Submit Button Text | |
$fields['comment_notes_after'] = ''; //Removes Form Allowed Tags Box | |
return $fields; | |
} | |
// Set the Comment Form fields | |
add_filter( 'comment_form_default_fields', 'wsm_comment_form_fields' ); | |
function wsm_comment_form_fields( $fields ) { | |
global $commenter, $req, $aria_req, $html5; | |
$fields = array( | |
'author' => '<p class="clearit comment-form-author">' . '<label for="author">' . __( 'Name', 'wsm' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . | |
'<input id="author" name="author" type="text" value="' . __( 'Name', 'wsm' ) . '" size="30"' . $aria_req . ' tabindex="1" /></p>', | |
'email' => '<p class="clearit comment-form-email"><label for="email">' . __( 'Email', 'wsm' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . | |
'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . __( 'Email', 'wsm' ) . '" size="30"' . $aria_req . ' tabindex="2" /></p>', | |
'url' => '<p class="clearit comment-form-url"><label for="url">' . __( 'Website', 'wsm' ) . '</label> ' . | |
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . __( 'Website', 'wsm' ) . '" size="30" tabindex="3" /></p>', | |
); | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment