• Resolved andystillalive

    (@andystillalive)


    Hi all, I’m a very very beginner of WP. I knew I can create some static pages through the admin panel but I would like to create a dynamic page with PHP code (contain a form) and redirect to a thank you page after the form submitted. I also want to define a static URL for that page e.g. https://www.abc.com/subscription/. May I know what is the most common approach? Thousand thanks. (Sorry for my poor English)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    you can create a custom page through custom page template functionality of WordPress. you can found more details in https://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/

    after all validation then you can put the action as thank you page in the form.

    AddWeb Solution

    (@addweb-solution-pvt-ltd)

    @andystillalive,

    Please follow below steps in order to create dynamic page using custom PHP Based wordpress code:

    1) You’ve to create custom template file in your current theme. (i.e. custompage.php) and which contains code below:

    <?php
     /*
     Template Name: Custom Page Template
     */
     
     get_header();
     
      // Here is your custom form whatever you want to add field.
     ?><form action="" method="post">
            Name : <input type="text" name="postTitle" value=""><br>
            Title : <input type="text" name="postContent" value="">
            <input type="submit" name="submit" value="submit">
      </form><?php
     get_footer();
    ?>

    2) Your template file is ready. Now, We’ve to handle the form data & store into our database for future use. So, that you’ve to add below code into your current theme’s function.php file.

    if(isset($_REQUEST['submit'])){
        $post_information = array(
          'post_title' =>  $_POST['postTitle'] ,
          'post_content' => $_POST['postContent'],
          'post_type' => 'page',
          'post_status' => 'pending'
      );
     $post_id = wp_insert_post( $post_information );
     if ( $post_id ) {
          wp_redirect( home_url() );// Here give your thank you page url.
          exit;
      }
    }

    Note : All Changes you done in function.php or other file are gone when you update theme. So prefer Child Theme

    Hope this will helps you.

    Thanks!

    Thread Starter andystillalive

    (@andystillalive)

    I did it. Thank you all you guys!

    AddWeb Solution

    (@addweb-solution-pvt-ltd)

    @andystillalive,

    Good to see that our provided solution worked for you. Can you please mark as “Accepted Solution” to make my put in efforts worth. Thanks!

    Thread Starter andystillalive

    (@andystillalive)

    Thanks a lot.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating a Dynamic Page’ is closed to new replies.