Title: Creat a plugin form
Last modified: September 1, 2016

---

# Creat a plugin form

 *  [M_Anaya](https://wordpress.org/support/users/m_anaya/)
 * (@m_anaya)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/creat-a-plugin-form/)
 * Hello
    I want to create a plugin that allows me to insert data on a table I create“
   tablename” and contian the following fields: id, name, email, gender (Mr or Mrs/
   Miss) Phone
 * _**it’s note a wp\_table it’s a customized table**
    
   
    Thank you for your help
 * My code :
 *     ```
       <?php
       /*
       Plugin Name: Formulaire M.ANAYA
       Version: 1.0
       Author: Mourad Anaya
       */
       global $wpdb;
   
       function html_form_code() {
       	echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
       	echo '<p>';
       	echo 'name (*) <br/>';
       	echo '<input type="text" name="pf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["pf-name"] ) ? esc_attr( $_POST["name"] ) : '' ) . '" size="40" />';
       	echo '</p>';
       	echo '<p>';
       	echo 'gender . (*) <br/>';
       	echo '<input type="text" name="pf-gender " pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["pf-gender "] ) ? esc_attr( $_POST["gender "] ) : '' ) . '" size="40" />';
       	echo '</p>';
       	echo '<p>';
       	echo 'Email (*) <br/>';
       	echo '<input type="email" name="pf-email" value="' . ( isset( $_POST["pf-email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
       	echo '</p>';
       	echo '<p>';
       	echo 'phone. (*) <br/>';
       	echo '<input type="text" name="pf-phone" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["pf-phone"] ) ? esc_attr( $_POST["cf-phone"] ) : '' ) . '" size="40" />';
       	echo '</p>';
       	echo '<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["pf-name"] );
       		$gender     = sanitize_text_field( $_POST["pf-genre"] );
       		$email   = sanitize_email( $_POST["pf-email"] );
       		$phone    = sanitize_text_field( $_POST["pf-phone"] );
   
       		// get the blog administrator's email address
       		$to = get_option( 'admin_email' );
   
       		$headers = "From: $name <$email>" . "\r\n";
   
       		// If email has been process for sending, display a success message
       		if ( wp_mail( $to, $subject, $message, $headers ) ) {
       			echo '<div>';
       			echo '<p>Merci de me contacter , attendez une réponse bientôt.</p>';
       			echo '</div>';
       		} else {
       			echo 'Une erreur inattendue est apparue';
       		}
       	}
       }
   
       function pf_shortcode() {
       	ob_start();
       	deliver_mail();
       	html_form_code();
   
       	return ob_get_clean();
       }
   
       add_shortcode( 'Marrakech_contact_form', 'pf_shortcode' );
   
       ?>
       ```
   

The topic ‘Creat a plugin form’ is closed to new replies.

## Tags

 * [creat](https://wordpress.org/support/topic-tag/creat/)
 * [customized](https://wordpress.org/support/topic-tag/customized/)
 * [form](https://wordpress.org/support/topic-tag/form/)
 * [table](https://wordpress.org/support/topic-tag/table/)

 * 0 replies
 * 1 participant
 * Last reply from: [M_Anaya](https://wordpress.org/support/users/m_anaya/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/creat-a-plugin-form/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
