WordPress.org

Ready to get started?Download WordPress

Forums

calling php file from form (3 posts)

  1. cajpersonalfinance
    Member
    Posted 6 years ago #

    Hi guys,

    I am learning php, and I am trying to write a simple form that calls a php file, and can't get it to work. Can anyone help??? I keep getting a 404 error. I am trying to get the file to call itself and evaluate the php.

    Thanks,

    Here is the code:

    <?php
    /*
    Template Name: Amort
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content" class="narrowcolumn">
    
    <h2>Amortization Schedule</h2>
    
    <form method=post action="amort.php">
          <input type="hidden" name="submitted">
          <input type="text" name="testinput">
          <input type="submit" name="submit" value="Submit">
    </form>
    
    <?php
    if (isset($_POST['submitted'])) {
    $test = $_POST['testinput'];
     echo '$test';
    }
    ?>
    
    </div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
  2. whooami
    Member
    Posted 6 years ago #

    youre doing things wrong.

    the 404 stems from this:

    <form method=post action="amort.php">

    youve coded this to be a template file for a page, but youre not using it in that way.

    I am trying to get the file to call itself and evaluate the php.

    What you ought to do is create a stand alone file. Include the necessary bits in that file that allow you to include the WP functions, like <?php get_sidebar(); ?> etc..

    That would be this:

    <?php
    /* Don't remove this line. */
    require('./wp-blog-header.php');
    ?>


    then
    put all that other stuff in it.

  3. cajpersonalfinance
    Member
    Posted 6 years ago #

    Thanks. That's a big help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags