Klausos Klausos
Klausos Klausos

Reputation: 16050

PHP: read value of input field

I have a very basic question about PHP. So, there is index.php that includes a form. This form contains input field field1:

index.php

    <div id="container1">
    <form name="optform" method="post" action="processing.php">
                <div class = "box">
                    <label for="field1"><span>Bla bla bla:</span></label>
                    <input type="text" class="input-text" value="5" size="11" maxlength="11" name="field1" id="field1">
                </div>
                <br/>
            <div class="buttons">
                <a href="" class="regular" onclick="click_function();return false;">Run</a>
            </div>
    </form>
    </div>

    <div id="container2">

    </div>

    <script language="javascript">
    function click_function() {
         $('#container2').load('processing.php');
    }
    </script>

I need to use the value from field1 in another PHP file called as processing.php. So, how can I read this value from processing.php? Should I do something like this in processing.php:?

processing.php

$field1value = $_POST["field1"];

Upvotes: 0

Views: 1342

Answers (4)

verisimilitude
verisimilitude

Reputation: 5108

Since the action of your is set to index.php, the data I feel will be POSTed to index.php itself. Instead of that, why not include action="processing.php" ?

Upvotes: 0

Bono
Bono

Reputation: 4849

Depending on how you want to do it you can store it in a $_SESSION
you can put the action attribute to "processing.php", which will submit all POST values to that file.
You could also include processing.php with your index.php

Upvotes: 0

slash197
slash197

Reputation: 9034

You should POST the form to processing.php

<form name="optform" method="post" action="processing.php">

Upvotes: 2

Quentin
Quentin

Reputation: 944009

The action attribute specifies the URL that the browser will submit to. That is currently index.php.

If you want to use code in processing.php to handle the form data, then index must include processing, not the other way around. (As the code stands, processing.php won't be involved at all, so can't include anything).

Alternatively, change the action to point to processing.php.

Upvotes: 6

Related Questions