Saturday, 17 August 2019 08:18

how to make a contact form in wordpress

Written by 
Rate this item
(0 votes)

Making a contact form is very popular in wordpress. 

Following code shows how i made a contact form.

 add_shortcode("mitsol_referral_contact_form", 'mitsol_referral_contact_form_replace_scode');    

function mitsol_referral_contact_form_replace_scode() {    

    $mrcf_html_content="";

    ob_start();

    mrcf_process_form();

    mrcf_html_form_code($mrcf_html_content);    

    /* Return the buffer contents into a variable */

    $msfb_html_content = ob_get_contents();

    /*Empty the buffer without displaying it. We don't want the previous html shown */

    ob_end_clean();

    /* The text returned will replace our shortcode matching text */

    return $msfb_html_content;

}

function mrcf_html_form_code($mrcf_html_content)

{            

    $mrcf_html_content.= '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">

   <!-- put all form html elements here --> 

    <input type="submit" id="mrcf-submitted" name="mrcf-submitted" class="mrcf-input-boxes" value="Send"         </form></div>';    

    echo $mrcf_html_content;    

}

function mrcf_process_form() {

   //check if form submitted then process submitted form data  

    if ( isset( $_POST['mrcf-submitted'] ) ) { 

   // process submitted form data here 

   }

}

Even if you know wordpress as a beginner you can understand 

above codes, first i defined a short code, in the shortcode function 

i defined a function mrcf_html_form_code() which puts form htmls 

in web page. And when form submitted, mrcf_process_form() 

function checks if form submitted or not and processes form data.

 

Hope you liked it, i described everything in a very simple way. 

don't forget to share it.

 

 

 

Read 1669 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.