• 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(); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter cajpersonalfinance

    (@cajpersonalfinance)

    Thanks. That’s a big help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘calling php file from form’ is closed to new replies.