• Resolved scapel

    (@scapel)


    Hello,
    I’am a beginer in plugin développement, and i am trying to create a page with an form inside…
    I create a class in which i use wp_insert_post and it is ok, but now, i don’t know how(or where!?) should i write code for my form…
    This class is instancied from admin menu.

    That’s an extract of code:

    <?php
    class register_page
    {
    	private $id_page;
    
    	public function __construct()
    	{
    		//Cree une page
    		$my_post = array(
    				'post_title'    => 'Inscription Individuelle Generee',
    				'post_content'  => 'This is my Page.',
    				'post_type'		=> 'page',
    				'post_status'   => 'publish',
    				'post_author'   => 1,
    		);
    
    		// Insert the post into the database
    		$id_page = wp_insert_post( $my_post );
    
    		//
    		//add_action('the_post', array($this,'register_page_construct'));
    		add_filter('publish_post', array($this,'register_page_construct'));
    
    		// write in table a log to controle this code is active
    		include_once plugin_dir_path( __FILE__ ).'/sql_tool.php';
    		$sqlTool = new sql_tool();
    		$sqlTool->debug_log("creation de la page");
    
    	}
    
    	public function register_page_construct($content)
    	{
    //		if ( is_page ($id_page) )
    //		{
    			echo "<h1>COUCOU</h1>";
    
    		    //write in table a log to controle this code is active
    			include_once plugin_dir_path( __FILE__ ).'/sql_tool.php';
    			$sqlTool = new sql_tool();
    			$sqlTool->debug_log("page_chargee");
    //		}
    	}
    
    }
    ?>

    Please help me!
    Thanks,
    Sebastien

Viewing 6 replies - 1 through 6 (of 6 total)
  • What is your form doing? Is it creating pages, or something else?

    Many plugins with forms (such as contact form 7) will insert the form into a page using a shortcode, and then do the processing behind the scenes using AJAX (You POST the form using AJAX and process it using PHP on the backend).

    A plugin like WooCommerce introduces forms into pages through hooks, and form processing takes place before the page header is rendered.

    Hi
    As ancawonka, mentioned, what exactly is the purpose you want to achieve, if it is just having a form in your content page, this can be managed with gravity form/ contact form 7 and most form plugins available, almost all of them provide shortcode/hooks.

    Thread Starter scapel

    (@scapel)

    Hi and thank you for these responses, but have got in my admin menu a form, in function of the responses filled in this form, i want create one or several pages with other forms for common (not admin) users, these “common user forms” are not static, it depend also of the responses the admin form had collected.
    I think use another plugin to do that (forms dependent of others) will be more complicate…

    Moderator bcworkz

    (@bcworkz)

    So your admin form is working fine, storing input values somewhere, yes? And now you want to present common user forms based on these values?

    Is this form to appear in the admin area or front end? If front end, for only logged in users, or anyone? Are you developing this as a plugin or child theme?

    I’d be inclined to present the common user form as a page based on a custom template. The template can get the admin values from where ever they are stored, then build the correct form accordingly.

    If this must be an admin area form, you could add an admin menu page that merely redirects to the page above. If you are developing as plugin, custom templates are tricky, but still possible.

    Thread Starter scapel

    (@scapel)

    Hi bcworkz,
    You are right, i have got an admin menu with a form. I store parameters from this form to create one or several pages, and to this step, all is ok. Now i would like create forms on these new pages for non admin users. These forms depend also of parameters records from the admin menu.
    (This is a plugin to performs a system to register runners for a race with different types of races).
    I’ll try by using template, and a returned to say if i success…
    (sorry for my englih, i hope to be not so horrible to read!)

    Thread Starter scapel

    (@scapel)

    Hello all,
    Yes, template is the solution! I can’t get directly paramters inside to build the form inside, but i can get the id of the page for which i associate in the data base the informations i need.
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Create page and content’ is closed to new replies.