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) Phoneit’s note a wp_table it’s a customized table
Thank you for your helpMy 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.