Better contact form 7 protection
All checks were successful
Generate Build Info / build-info (push) Successful in 1s
All checks were successful
Generate Build Info / build-info (push) Successful in 1s
This commit is contained in:
26
dapper.php
26
dapper.php
@@ -1250,18 +1250,34 @@ if (class_exists('WPCF7')) {
|
||||
$checkbox_html = '
|
||||
<div class="dapper-cf7-human-check" style="margin: 1.5em 0; padding: 1em; background: #f8f9fa; border: 1px solid #ccd0d4; border-radius: 4px; text-align: center;">
|
||||
<label style="font-size: 1.1em; cursor: pointer; user-select: none;">
|
||||
<input type="checkbox" name="dapper_cf7_human_confirm" id="dapper_cf7_human_confirm" value="1" required style="transform: scale(1.4); margin-right: 0.8em; vertical-align: middle;">
|
||||
<input type="checkbox" name="dapper_cf7_human_confirm" id="dapper_cf7_human_confirm_' . uniqid() . '" value="1" required style="transform: scale(1.4); margin-right: 0.8em; vertical-align: middle;">
|
||||
I am human / not a robot
|
||||
</label>
|
||||
<input type="hidden" name="dapper_cf7_human_token" id="dapper_cf7_human_token" value="">
|
||||
<input type="hidden" name="dapper_cf7_human_token" id="dapper_cf7_human_token_' . uniqid() . '" value="">
|
||||
<input type="hidden" name="dapper_cf7_human_time" value="' . time() . '">
|
||||
<p style="margin: 0.6em 0 0; font-size: 0.9em; color: #555;">Quick check to help stop spam. Thanks!</p>
|
||||
</div>';
|
||||
|
||||
// Insert just before the submit button / </form>
|
||||
$form = preg_replace( '/(<button[^>]*type=["\']submit["\'][^>]*>.*?<\/button>)/is', $checkbox_html . '$1', $form );
|
||||
// 1. Try to insert before the submit input/button (most common cases)
|
||||
// Look for <input type="submit"...> or <button type="submit">...</button>
|
||||
$form = preg_replace(
|
||||
'/(<(?:input|button)[^>]*type=["\']submit["\'][^>]*>)/i',
|
||||
$checkbox_html . '$1',
|
||||
$form,
|
||||
1 // limit to first match
|
||||
);
|
||||
|
||||
// Fallback: if no <button type="submit"> found, put before </form>
|
||||
// 2. If that didn't work (rare), try before the wrapping <p> of submit
|
||||
if ( strpos( $form, $checkbox_html ) === false ) {
|
||||
$form = preg_replace(
|
||||
'/(<p[^>]*>[\s\S]*?(?:<input[^>]*type=["\']submit["\'][^>]*>|<\/button>)[\s\S]*?<\/p>)/i',
|
||||
$checkbox_html . '$1',
|
||||
$form,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Ultimate fallback: just before </form>
|
||||
if ( strpos( $form, $checkbox_html ) === false ) {
|
||||
$form = str_replace( '</form>', $checkbox_html . '</form>', $form );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user