0

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"];
1
  • Include processing.php in index.php and execute the code under condition that POST is set. This is one option. You could also set the form action to processing.php and then redirect back to index. Commented May 21, 2012 at 11:02

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

4 Comments

using one common entry point for the app is usually better, I would vote for index.php
@KlausosKlausos You can now access that value in processing.php. If you still want to use that value in index.php though you will have to do it differently (include processing.php for example)
@Bono: I want to see field1 in processing.php. So, I assume it's fine now.
@KlausosKlausos: Why have you included processing.php at the top? since the action is now set to processing.php, the POSTed data will be visible in that file..
2

You should POST the form to processing.php

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

Comments

0

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

Comments

0

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" ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.