1. Go to this page and download the library: Download anttiviljami/wp-libre-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anttiviljami / wp-libre-form example snippets
/**
* ReCaptcha for WP Libre Form
*/
add_filter( 'wplf_validate_submission', 'wplf_recaptcha' );
function wplf_recaptcha( $return ) {
// skip this validation if submission has already failed
if ( ! $return->ok ) {
return $return;
}
$secret = RECAPTCHA_KEY; // substitute with your own secret recaptcha key string
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query([
'secret' => $secret,
'response' => $_POST['g-recaptcha-response'],
])
],
];
$context = stream_context_create( $options );
$result = file_get_contents( 'https://www.google.com/recaptcha/api/siteverify', false, $context );
$captcha_obj = json_decode( $result );
if ( false === $captcha_obj->success ) {
$return->ok = 0;
$return->error = __("Please prove you're not a robot before submitting.");
}
return $return;
}
add_action( 'wplf_post_validate_submission', 'my_email_thankyou' );
function my_email_thankyou( $return ) {
// recipient details from submission
$name = sanitize_text_field( $_POST['name'] );
$email = sanitize_email( $_POST['email'] );
// email subject
$subject = __( 'Thank You For Submitting A Form' );
// text body of email
$body = wp_sprintf( __('Thanks, %s for clicking Submit on this glorious HTML5 Form!'), $name );
// send the email
wp_mail( $email, $subject, $body );
}
$wplf = wplf();
$plugin = new YourPlugin();
$wplf->plugins->register([
"name" => "YourPlugin", // The name you wish to show on the WPLF plugin page. Willl also be used to access public methods in your plugin
"description" => "What your plugin does in a sentence or two",
"link" => "https://toyourplugin.com", // Plugin URL. Can be wordpress.org or pretty much any URL where you can download the plugin
"version" => YOUR_PLUGIN_VERSION, // Define a constant containing your plugin version
"instance" => $plugin, // Your plugin, instantiated. Users can access your public methods
"settings_page" => [$plugin, "render_settings_page"], // Function that renders your settings page, or a string that contains the link to it. Leave empty to disable.
]);
add_filter( 'wplf_import_html_template', function ( $template, $form_id ) {
$some_form_id = 123;
if ( $form_id === $some_form_id ) {
// You can also render Twig templates and similar here
return file_get_contents( '/path/to/template/file.html' );
}
return $template;
}, 10, 2 );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.