Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php and form fields?

Status
Not open for further replies.

Sidro

MIS
Joined
Sep 28, 2002
Messages
197
Location
US
Hi,
In a form with text fields,
how do I get the values in a text field, give it to php to be process, and then take the processed result and stick it back into the text field value and have php submit it?
Thanks in advance.
Example,

<input type=&quot;text&quot; name=&quot;Input&quot;>

<?php

//How can php receive the values in the test field named, &quot;Input&quot;?
?>
 
The form input will be inside a &quot;<FORM...>&quot; tag. That tag will specify a &quot;method&quot; attribue of &quot;GET&quot; or &quot;POST&quot;.

If you submit a form to a PHP script, the values will appear automagically in the PHP predefined variables $_GET or $_POST, depending, respectively, which method you specified in your form. There is some good documentation for this in the PHP online manual:
I don't understand what you want to do with the value after you have processed it. I think that your question indicates a misunderstanding about how web applications work.

A console application is a continuous dialog between a user and the appliction. The program runs the whole time, reacting to user input and producing output for the user.

Web applications are not continuous. When you point your browser to a script on a web server, the script runs and produces output for your browser to render. Then the script stops running completely. So instead of a single, long conversation, web applications are sets of multiple short conversations between a user and the application. Unless the browser is actively fetching information from a script running on a server, your application is not running.

So in terms of the web, it seems to me what you want to do is accept input, have PHP process it and produce a second form which the user can submit to another script.

What follows is a short PHP script that demonstrates the discontinuity of web apps. The first time it is run, nothing will have been submitted to the script, so the script produces a blank form. If form data has been submitted, the script takes the text entered in a field named &quot;the_text&quot;, reverses it, then outputs the form with the input field pre-populated with the submitted string reversed:

Code:
<?php

if (array_key_exists('the_text', $_POST))
{
        $the_string = strrev($_POST['the_text']);
}
else
{
        $the_string = '';
}

print '
<html><body>
<form method=&quot;post&quot; action=&quot;test_reverse.php&quot;>
<input type=&quot;text&quot; name=&quot;the_text&quot; value=&quot;' . $the_string . '&quot;>
<input type=&quot;submit&quot;>
</form></body></html>';

?>

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top