I used the following code to get variable sent via a form but now I am wondering if I can get the variable names too so I can display it nicely in an email.
-MattPHP Code:<?php
if (isset($submit)) {
foreach($_POST as $i) {
print "$i<br>";
}
}
?>
Printable View
I used the following code to get variable sent via a form but now I am wondering if I can get the variable names too so I can display it nicely in an email.
-MattPHP Code:<?php
if (isset($submit)) {
foreach($_POST as $i) {
print "$i<br>";
}
}
?>
Wont that display the value of each? Or is that what you're trying to accomplish?
Nevermind, you already knew that...
Here is a test script of what information that code gets, I want to get the name="" attribute too and not just the value=""
http://cpradio.net/Test.php
-Matt
Try this:
PHP Code:<?php
if (isset ($submit)) {
while (list ($name, $value) = each ($_POST)) {
echo "$name == $value<br>\n";
}
}
?>
that didnt work :(
This works for me:
PHP Code:<?php
if ($action == 'show') {
while (list ($name, $value) = each ($_POST)) {
echo "$name == $value<br>\n";
}
} else {
echo '<form action="work.php" method="post">
<input type="hidden" name="action" value="show">
<input type="text" name="fun"><br>
<input type="submit">
</form>';
}
?>
you can see it here: http://www.vbshelf.com/work.php
ahh, it works. I had placed your code beneath mine and it wouldn't run b/c the pointer was at the end of $_Post
So everything is good?
yep, now i have a universal contact form/anything you want form
FYI
if (isset($_POST["submit"])) {
if globals are turned off then submit will not get noticed. submit is just like any other variable from a form.
Same thing for ACTION, Hobo.
OKAY?PHP Code:if ($_POST['action'] == 'show') {
In later versions will globals be turned off automatically?Quote:
Originally posted by scoutt
FYI
if (isset($_POST["submit"])) {
if globals are turned off then submit will not get noticed. submit is just like any other variable from a form.
Hobo: I dont plan on using action as its just a worthless slot for me. I just plan on using that code to create Emails on the fly from any form.
-Matt
Yes, starting in 4.2, it will be turned off by default.Quote:
Originally posted by cpradio
In later versions will globals be turned off automatically?
Hobo: I dont plan on using action as its just a worthless slot for me. I just plan on using that code to create Emails on the fly from any form.
-Matt
Matt:That post was directed at myself. Not you.
oh okay :)
Will the option to turn them on still be existant or is it forcing them to be off?
you can still turn them on, but it is not recommended for security and speed issues.
I've grown to love the superglobals anyways :)
damn, i now have to rewrite about 40 pages of code :(
wait maybe not, is there any way to force globals on at runtime?
yes you can set the globals on at runtime,
ini_set("register_globals", 1);
that iwll set it to 1, which is on. 0 is off.
You could mimic it by using the code I gave you below:
Okay, I can't remember how to do it. I'll get back to you.PHP Code:<?php
while (list ($name, $value) = each ($_POST)) {
//something
}
?>
Well, the reason I asked is with ini_set("register_globals",1); I can now go back to my old php scripts add that line and not worry about them not working in 4.2
I would test it first on a couple of pages first before your whole site. I tried a couple of other things like that and I remember having issues since the master setting was the other way.
im almost positive my hosting service will have them on as its more convinent, so im not too worried.
but when the switch occurs I will test it locally first.
:)