Forums

What went wrong? my plugin (4 posts)

  1. m1234x5
    Member
    Posted 1 year ago #

    <?php
    /*
    Plugin Name:My Plugin
    */
    
    function my_function($text){
    	if(isset($_POST["name"])) {
    		$name = $_POST['name'];
    	} else {
    		echo "
    			<form method='post' action='options.php'>
    			name : <inputtype='text' name='name'>
    			<input type='submit' value='submit'>
    			</form>
    		";
    	}
    
    	$text = str_replace('foo',$name,$text); //replace $name -> foo
    	return $text;
    }
    
    add_filter('the_content','my_function');
    ?>
  2. webjunk
    Member
    Posted 1 year ago #

    From a quick look I see:
    inputtype='text'
    which needs a space like:
    input type='text'

  3. m1234x5
    Member
    Posted 1 year ago #

    <?php
    /*
    Plugin Name:My Plugin
    */
    
    function my_function($text){
    	if(isset($_POST["name"])) {
    		$name = $_POST['name'];
    	} else {
    		echo "
    			<form method='post' action='options.php'>
    			name : <input type='text' name='name'>
    			<input type='submit' value='submit'>
    			</form>
    		";
    	}
    
    	$text = str_replace('foo',$name,$text); //replace $name -> foo
    	return $text;
    }
    
    add_filter('the_content','my_function');
    ?>

    ==========================================================
    path : /wp-content/plugins/myplugin/options.php

    1. <form method='post' action='options.php'>

    result = Object not found!

    or

    2. <form method='post' action='wp-content/plugins/myplugin/options.php'>

    result = Fatal error: Call to undefined function add_filter() in D:\xampp\htdocs\thwordpress\wp-content\plugins\myplugin\options.php on line 23
    ======================================================================

  4. elfin
    Moderator
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags