Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

Contact form in Wordpress



Contact form in Wordpress


Hello  All,

Mostly Use Contact Form In Web site.

I am Create simple code  for add contact form in wordpress.

It's Only Example No Plugin required. You can also Custimise;

I am create Name,Email,Message Fild in wordpress;

CREATE TABLE IF NOT EXISTS `wp_myphpinformation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  `message` varchar(225) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

I am create this table in my php admin.

Create templete In Wordpress


/*
Template Name: My Custom Page
*/

Copy the page.php of your current theme and change name like contactform.php

After adding a comment and check with your admin this template.


I am here add full Ecample Code Check IT. I hope you like;

it's contactform.php

<?php

/*
Template Name: My Custom Page
*/
?>
<?php get_header(); ?>
<?php
        if (!empty($_POST)) {
        global $wpdb;
            $table = wp_myphpinformation;
            $data = array(
                'name' => $_POST['yourname'],
                'email'    => $_POST['email'],
                'message' =>  $_POST['message']
            );
            $format = array(
                '%s',
                '%s',
                '%s'
            );
            $success=$wpdb->insert( $table, $data, $format );
            
            
            if($success){
            echo 'data has been save' ; 
}
}
else   {
?>
        <form method="post">
       

Contact Me

        <input type="text" name="yourname"/><br />
        <input type="text" name="email"/><br />
        <textarea name="message"></textarea><br />//textarea code
        <input type="submit"/>
        </form>

       <?php }  ?>
       <div class="contact">
       <table>
        <tr>
        <td>Name</td>
        <td>Email</td>
        <td>Message</td>
        </tr>
       <?php 
       
       $results = $wpdb->get_results( 'SELECT * FROM wp_myphpinformation', OBJECT );
       
       foreach($results as $result){?>
        
        <tr>
        <td>php echo $result->name; ?></td>
        <td>php echo $result->email; ?></td>
        <td>php echo $result->message; ?></td>
        </tr>
        
        
        
      <?php }
       
       ?>
       </table>
       </div>

<?php get_footer(); ?>





0 komentar:

Post a Comment

Contact form in Wordpress