WordPress: Implement basic HTML form functionality to retrieve data and visualize the results

I have experience in HMTL/PHP but I cannot understand how someone could implement this basic functionality in WordPress. I could not find an article or web page on their website or by searching through the internet.

I want to create a basic html form, pass some data as select queries in a database and visualize back the results paginated.

Read More

In traditional PHP we are using “action” in order to send the form data through POST or GET to the action page and then with some PHP code we can fetch the data and visualize it with tables etc.

I cannot understand how to do such a thing in a wordpress page. Where the action parameter should point to? How could I implement this basic functionality in WordPress?

Please could someone help?

Related posts

Leave a Reply

2 comments

  1. This is the mode to develop a separated .php file which uses your wordpress theme and can access to almost all wordpress functions:

    <?php include(’wp-blog-header.php’); ?>
    <?php get_header(); ?> 
    <!– Your code here –>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    Then you can use all WordPress functions cited here: http://codex.wordpress.org/Function_Reference
    You can save this file anywhere, but be sure to insert correct path to wp-blog-header and there must not be any prohibiting .htaccess

    This is the way to insert php code into a wordpress post:
    You have to use this plugin http://wordpress.org/plugins/allow-php-in-posts-and-pages/
    Then create a post and use [php] [/php] to insert your php code and open it. Look at the address bar. This it the URL to access this post. Use it as action parameter in your form. Then control $_REQUEST[] in your php code to extract parameters received from your form.
    Now you can control this post as any other normal wordpress post from the wordpress admin panel.

  2. You need to create custom wordpress templates for pages in your theme. Here i use templates
    1.form-page.php — with template name “Form-page-template” and
    2.form-page-action.php —with template name “Form-page-action-template”

    form-page.php

    <?php
    /*
    Template Name: Form-page-template
    */
    ?>
    <?php get_header(); ?>
    <form method="post" action="http://yourdomain.com/form-page-action/" name="input-form"/>
    
    <!-- form contents -->
    
    </form>   
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    You just save this template inside your theme : location => like wp-contents/themes/your-theme/form-page.php . and this will add Form-page-template in your theme .Now create a page inside from wordpress dashboard through pages->addnew ,here i give page name “form-page” and select template for page from right pannel,here we need to select “Form-page-template” that we created early.

    Now we have the page url :: http://yourdomain.com/form-page/ where we can see our form,now create form-action-page.

    2.form-page-action.php

    <?php
    /*
    Template Name: Form-page-action-template
    */
    ?>
    <?php get_header(); ?>
    <!-- Your action page contents goes here -->
    <?php
    //getting input etc.. you need to do
    $input = $post['input'];
    
    ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    Now you need to save this template inside your theme as above, Create a new page for this template as said above here i creating a page “form-page-action” with template “Form-page-action-template” so here i get a page url for our
    action page like :: http://yourdomain.com/form-page-action/ , and you need to use this url as the action url in your form page.and this way you can add your form action page inside wordpress theme.

    You can edit the contents of these page inside from wordpress like=> Appreance -> Editor , select the templates to edit.