Nấm Lùn
Nấm Lùn

Reputation: 1275

PHP : How to post form data via another file?

I have 2 files : index.php, form.php.

form.php:

<?php

if (isset($_POST['submit'])){
    echo "OK";
    // do something with post data

}

?>
    <form method="post" name="myform">
        <input type="text" name="name" />
        <input type="submit" name="submit" value="SUBMIT" />
    </form>

I call form.php by typing in browser address bar: **mysite/index.php?act=form**

In index.php I have these line:

    <?php

    switch($_REQUEST['act']){
        case "form":
            include("form.php"); break;

    }
...

But I had nothing (in form.php) when the form was submitted. All that I want is get posted data in form.php, not in index.php.

What was I wrong here?

Thansk for your time!

Upvotes: 2

Views: 5652

Answers (2)

xdazz
xdazz

Reputation: 160833

So you need add the action attribute of the form:

<form action="/index.php?act=form" method="post" name="myform">

Upvotes: 2

WatsMyName
WatsMyName

Reputation: 4478

change your line in form.php

<form method="post" name="myform" action="form.php">

or

<form method="post" name="myform" action="index.php?act=form">

Upvotes: 7

Related Questions