By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,180 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

getting $_POST variables from form in a function

P: n/a
I've loaded various thoughts I've collected into mysql. I want to write an
app, all in one file, that has the following features:

1. On initial entry, selects and displays the thoughts ( might add
pagination later - there aren't alot of records, for now.)
2. This main page includes separate forms near the top with submit buttons
to search, add a thought, view all thoughts, etc. The action for each form
is to call this same page. The submit buttons and thoughts are printed from
a function.
3. In the main logic, I am trying to do a $_POST and if isset() on each
submit button name and then call a corresponding function, do whatever it
has to do, unset the form variable and continue back to the main display.

The problem is that it's not calling any functions. The error log says that
the name of each submit button in my $_POST[] statements in the main logic
is an undefined index. I presume that they are undefined in the main logic
because the forms were defined in a function.

Is there anyway to access, in the same page, form variables that were
declared in a function on that page?

Thanks!
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

On 26-Oct-2003, "Jenkins" <ne**@djenkins.nu> wrote:
I've loaded various thoughts I've collected into mysql. I want to write an
app, all in one file, that has the following features:

1. On initial entry, selects and displays the thoughts ( might add
pagination later - there aren't alot of records, for now.)
2. This main page includes separate forms near the top with submit buttons
to search, add a thought, view all thoughts, etc. The action for each form
is to call this same page. The submit buttons and thoughts are printed
from
a function.
3. In the main logic, I am trying to do a $_POST and if isset() on each
submit button name and then call a corresponding function, do whatever it
has to do, unset the form variable and continue back to the main display.

The problem is that it's not calling any functions. The error log says
that
the name of each submit button in my $_POST[] statements in the main
logic
is an undefined index. I presume that they are undefined in the main logic
because the forms were defined in a function.

Is there anyway to access, in the same page, form variables that were
declared in a function on that page?


Barring typos I think this illustrates what you want to do:

myscript.php:
<?php

if (isset($_POST['submit'))
{
$whichbutton = $_POST['submit'];
$somefieldvalue = $_POST['somefield'];
if ($whichbutton == 'Red')
// do red things
if ($whichbutton == 'Blue')
// do blue things
}
else
{
$whichbutton = 'None';
$somefieldvalue = 'Starting value';
}
?>
<HTML> ....

<p>The last button pushed was <? echo $whichbutton; ?></p>
<form action="myscript.php" method=post>
<input type=text name=somefield value="<? echo $somefieldvalue; ?>">
....
<input type=submit name=submit value="Red">
<input type=submit name=submit value="Blue">
</form>
....

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.