Browse Source

Simple honeypot (fixes #134)

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

6
inc/helpers/namespace.php

@ -259,6 +259,10 @@ function handle_contact_form_submission() {
return false; // Security check failed. return false; // Security check failed.
} }
if ( isset( $_POST['submitted'] ) ) { if ( isset( $_POST['submitted'] ) ) {
// Check the fake anti-spam honeypot field.
if ( ! empty( $_POST['firstname'] ) ) {
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 = [];
$name = ( isset( $_POST['visitor_name'] ) ) ? $_POST['visitor_name'] : ''; $name = ( isset( $_POST['visitor_name'] ) ) ? $_POST['visitor_name'] : '';
@ -315,7 +319,7 @@ function handle_contact_form_submission() {
} }
return $output; return $output;
} }
return; return false;
} }
/** /**

6
partials/contact-form.php

@ -22,6 +22,12 @@ $contact_form_response = \Aldine\Helpers\handle_contact_form_submission();
<?php endif; ?> <?php endif; ?>
<?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;">
<input type="text" name="firstname" id="firstname"/>
<label for="firstname">
<?php _e( 'Keep this field blank (required)', 'pressbooks-aldine' ); ?>
</label>
</p>
<p class="form__row"> <p class="form__row">
<input id="contact-name" <input id="contact-name"
<?php <?php

Loading…
Cancel
Save