• Resolved Matthew

    (@kidsguide)


    What is wrong with this plugin?

    <?php
    /*
    Plugin Name: Contact Form Shortcode
    Description: Put shortcode [contactform] in a post or page.
    */
    
    <form action="post">
    <h2>Contact Form</h2>
    Name <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="Name" size="28" />
    
    E-mail <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="E-mail" size="30" />
    
    Subject <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="Subject" size="30" />
    
    Text <textarea style="width: 420px; height: 150px;" cols="20" name="Text" rows="10"></textarea>
    
    <input type="submit" value="Send Email" />
    
    </form>
    
    class Contact Form Shortcode {
         function contactform_func() {
                return "content = $content";
         }
    }
    add_shortcode( 'contactform', array( 'Contact Form Shortcode', 'contactform_func' ) );
    </?php

Viewing 2 replies - 1 through 2 (of 2 total)
  • Several things…

    1. You output the form directly in the code. There’s no action or callback or shortcode that calls it – it’s output as soon as that file is included in the system.
    2. You don’t close the PHP tags before you start the HTML output.
    3. Your class name is wrong. You can’t have spaces in a class name. You can change them to underscaores like Contact_Form_Shortcode.
    4. You don’t define the value for $content anywhere so that will be blank when the shortcode is actually called.
    5. Not 100% essential, but the function should be defined as static as you don’t need the object to be instantiated before the function can be used.

    When you’re devloping plugins or themes you really need to turn on dubugging. it will show you where the errors are.

    It should be more like (just put in the correct way, not fully tested):

    <?php
    /*
    Plugin Name: Contact Form Shortcode
    Description: Put shortcode [contactform] in a post or page.
    */
    class Contact_Form_Shortcode {
         static function contactform_func() {
    		 ob_start ();
    ?>
    <form action="post">
    <h2>Contact Form</h2>
    Name <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="Name" size="28" />
    
    E-mail <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="E-mail" size="30" />
    
    Subject <input style="width: 220px; height: 20px;" type="text" maxlength="25" name="Subject" size="30" />
    
    Text <textarea style="width: 420px; height: 150px;" cols="20" name="Text" rows="10"></textarea>
    
    <input type="submit" value="Send Email" />
    
    </form>
    <?
    		 $content = ob_get_contents ();
    		 ob_end_clean ();
    
             return $content;
         }
    }
    add_shortcode( 'contactform', array( 'Contact Form Shortcode', 'contactform_func' ) );
    Thread Starter Matthew

    (@kidsguide)

    Thanks so much catacaustic!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘What is wrong with this plugin?’ is closed to new replies.