Skip to content

Instantly share code, notes, and snippets.

@richtabor
Last active July 11, 2016 13:35
Show Gist options
  • Save richtabor/8de5c4e04c7fde2d4741573bf4f4df0d to your computer and use it in GitHub Desktop.
Save richtabor/8de5c4e04c7fde2d4741573bf4f4df0d to your computer and use it in GitHub Desktop.
/**
* Customize the default success message presented on the contact template.
*/
function prefix_custom_success_msg() {
esc_html_e('Wohoo! We have received your mail!', 'mark');
}
add_filter( 'bean_contactform_success_msg', 'prefix_custom_success_msg' );
/**
* Customize the default error message presented on the contact template.
*/
function prefix_custom_error_msg() {
esc_html_e('Oh no..... theres an error.', 'mark');
}
add_filter( 'bean_contactform_error_msg', 'prefix_custom_error_msg' );
/**
* Customize the label for the 'Name' field.
*/
function prefix_custom_name_label() {
esc_html_e('First Name', 'plate');
}
add_filter( 'bean_contactform_name_label', 'prefix_custom_name_label' );
/**
* Customize the label for the 'Email' field.
*/
function prefix_custom_email_label() {
esc_html_e('Email Address', 'plate');
}
add_filter( 'bean_contactform_email_label', 'prefix_custom_email_label' );
/**
* Customize the label for the 'Message' field.
*/
function prefix_custom_message_label() {
esc_html_e('Messages', 'plate');
}
add_filter( 'bean_contactform_message_label', 'prefix_custom_message_label' );
/**
* Add a custom text (required) field to the contact form.
*/
function prefix_add_twitter_field() { ?>
<div class="group">
<label for="messageTwitter"><?php esc_html_e('Twitter Username', 'mark'); ?></label>
<input type="text" name="messageTwitter" id="messageTwitter" value="<?php if(isset($_POST['messageTwitter'])) echo esc_html($_POST['messageTwitter']);?>" class="required requiredField" required/>
</div>
<?php
}
add_action( 'bean_after_contactform_emailfield', 'prefix_add_twitter_field' );
/**
* Add custom validation if neccessary.
*/
function prefix_add_twitter_required_validation() {
if(trim($_POST['messageTwitter']) === '') {
$hasError = true;
} else {
$twitter = trim($_POST['messageTwitter']);
}
}
add_action( 'bean_after_contactform_errors', 'prefix_add_twitter_required_validation' );
/**
* Add the new data to the email generated and sent to you.
* In this example, we're just catching the current $body and attaching the Twitter username data to it.
*/
function prefix_custom_emailbody( $body ) {
$twitter = 'Twitter Usermame: ' . trim($_POST['messageTwitter']);
// the "\n\n" adds a double-space between your other form fields.
return $body . "\n\n" . $twitter;
}
add_filter( 'bean_contactform_emailbody', 'prefix_custom_emailbody' );
/**
* Customize the subject line of the email.
*/
function prefix_custom_emailsubject( $subjectline ) {
$subjectline = 'Hey there!';
return $subjectline;
}
add_filter( 'bean_contactform_emailsubject', 'prefix_custom_emailsubject' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment