Quantcast
Viewing all articles
Browse latest Browse all 5998

clubbinside on "Datepicker in contact form"

thank you for the help in advance. I have been trying to find tutorial about building my own contact form for wordpress (without plugin). I thought i found one, and this is where the trouble started ...

(i have googled, searched and was digging on the internet for days, i need to ask here, it seems to be there are helpful people around...)

[ Moderator note: if you use <li> then please wrap it in <ol> or <ul> or it breaks the formatting. ]

<li>wp_mail doesnt work: it seems to go through after clicking on submit, but never arrives... :( </li>
<li>if somebody would be so kind to guide, or explain to me how to implement datepicker into this contact form, and how to handle the data from it and include to the email (and where was i mistaken?) would be really really appreciated.</li>

here is the code

<?php
/*
Plugin Name: Self Catering Contact form plugin
Plugin URI: http://example.com
Description: Simple non-bloated WordPress Contact Form use [contact_form]shortcode
Version: 1.0
Author: Agbonghama Collins
Author URI: http://w3guy.com
*/

function html_form_code() {
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
    echo '<p>';
    echo 'Your Name (required) <br />';
    echo '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="40" />';
    echo '</p>';
    echo '<p>';
    echo 'Your Email (required) <br />';
    echo '<input type="email" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" />';
    echo '</p>';
    echo '<p>';
    echo 'Subject (required) <br />';
    echo '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value="' . ( isset( $_POST["cf-subject"] ) ? esc_attr( $_POST["cf-subject"] ) : '' ) . '" size="40" />';
    echo '</p>';
    echo '<p>';
    echo 'Your Message (required) <br />';
    echo '<textarea rows="10" cols="35" name="cf-message">' . ( isset( $_POST["cf-message"] ) ? esc_attr( $_POST["cf-message"] ) : '' ) . '</textarea>';
    echo '</p>';
    echo 'Select date <br />';
    echo '<p><input type="text" id="datepicker" name="datepicker" value="' . ( isset( $_POST["datepicker"] ) ? esc_attr( $_POST["datepicker"] ) : '' ) . '" size="40" />'.'</p>';
    echo '<p><input type="submit" name="cf-submitted" value="Send"/></p>';
    echo '</form>';
}
function deliver_mail() {

    // if the submit button is clicked, send the email
    if ( isset( $_POST['cf-submitted'] ) ) {

        // sanitize form values
        $name    = sanitize_text_field( $_POST["cf-name"] );
        $email   = sanitize_email( $_POST["cf-email"] );
        $subject = sanitize_text_field( $_POST["cf-subject"] );
        $message = esc_textarea( $_POST["cf-message"] );
        $datepicker = sanitize_text_field($_POST["datepicker"]);

        // get the blog administrator's email address
        $to = 'atesz@atesz.co.uk';

        $headers = "From: example@yourdomainname.com" . "\r\n";

        // If email has been process for sending, display a success message
        if ( wp_mail( $to, $subject, $message, $headers ) ) {
            echo '<div>';
            echo '<p class="red">sent</p>';
            echo '</div>';
        } else {
            echo 'An unexpected error occurred';
        }
    }
}
function cf_shortcode() {
    ob_start();
    deliver_mail();
    html_form_code();

    return ob_get_clean();
}

add_shortcode( 'contact_form', 'cf_shortcode' );

This is my contact-form.php which i would like to act as a plugin (instead of using cform7, etc..) Mainly, i would like to understand how it works and this way try to progress with wordpress...

Thank you very much for taking your time reading this post.


Viewing all articles
Browse latest Browse all 5998

Trending Articles