Browse Source

Randomize field.

pull/135/head
Dac Chartrand 7 years ago
parent
commit
e879b2534c
  1. 7
      inc/helpers/namespace.php
  2. 5
      partials/contact-form.php

7
inc/helpers/namespace.php

@ -9,6 +9,7 @@ namespace Aldine\Helpers;
use function \Pressbooks\Metadata\book_information_to_schema; use function \Pressbooks\Metadata\book_information_to_schema;
use function \Pressbooks\Metadata\is_bisac; use function \Pressbooks\Metadata\is_bisac;
use function \Pressbooks\Utility\str_starts_with;
use Pressbooks\Book; use Pressbooks\Book;
/** /**
@ -260,8 +261,10 @@ function handle_contact_form_submission() {
} }
if ( isset( $_POST['submitted'] ) ) { if ( isset( $_POST['submitted'] ) ) {
// Check the fake anti-spam honeypot field. // Check the fake anti-spam honeypot field.
if ( ! empty( $_POST['firstname'] ) ) { foreach ( $_POST as $pkey => $pval ) {
return false; // Honeypot failed. if ( str_starts_with( $pkey, 'firstname' ) && ! empty( $pval ) ) {
return false; // Honeypot failed.
}
} }
$contact_email = get_option( 'pb_network_contact_email', get_option( 'admin_email' ) ); $contact_email = get_option( 'pb_network_contact_email', get_option( 'admin_email' ) );
$output = []; $output = [];

5
partials/contact-form.php

@ -11,6 +11,7 @@
$pb_network_contact_form_title = get_option( 'pb_network_contact_form_title' ); $pb_network_contact_form_title = get_option( 'pb_network_contact_form_title' );
$contact_form_title = ( ! empty( $pb_network_contact_form_title ) ) ? $pb_network_contact_form_title : __( 'Contact Us', 'pressbooks-aldine' ); $contact_form_title = ( ! empty( $pb_network_contact_form_title ) ) ? $pb_network_contact_form_title : __( 'Contact Us', 'pressbooks-aldine' );
$contact_form_response = \Aldine\Helpers\handle_contact_form_submission(); $contact_form_response = \Aldine\Helpers\handle_contact_form_submission();
$honeypot = 'firstname' . rand();
?> ?>
@ -23,8 +24,8 @@ $contact_form_response = \Aldine\Helpers\handle_contact_form_submission();
<?php wp_nonce_field( 'pb_root_contact_form', 'pb_root_contact_form_nonce' ); ?> <?php wp_nonce_field( 'pb_root_contact_form', 'pb_root_contact_form_nonce' ); ?>
<input type="hidden" name="submitted" value="1"> <input type="hidden" name="submitted" value="1">
<p class="form__row" style="display:none;"> <p class="form__row" style="display:none;">
<input type="text" name="firstname" id="firstname"/> <input type="text" name="<?php echo $honeypot; ?>" id="<?php echo $honeypot; ?>"/>
<label for="firstname"> <label for="<?php echo $honeypot; ?>">
<?php _e( 'Keep this field blank (required)', 'pressbooks-aldine' ); ?> <?php _e( 'Keep this field blank (required)', 'pressbooks-aldine' ); ?>
</label> </label>
</p> </p>

Loading…
Cancel
Save