|
-
May 30th, 2002, 09:31 AM
#1
Thread Starter
Fanatic Member
$_post
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.
PHP Code:
<?php
if (isset($submit)) {
foreach($_POST as $i) {
print "$i<br>";
}
}
?>
-Matt
-
May 30th, 2002, 11:11 AM
#2
Stuck in the 80s
Wont that display the value of each? Or is that what you're trying to accomplish?
-
May 30th, 2002, 11:14 AM
#3
Stuck in the 80s
Nevermind, you already knew that...
-
May 30th, 2002, 12:00 PM
#4
Thread Starter
Fanatic Member
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
-
May 30th, 2002, 12:01 PM
#5
Stuck in the 80s
Try this:
PHP Code:
<?php
if (isset ($submit)) {
while (list ($name, $value) = each ($_POST)) {
echo "$name == $value<br>\n";
}
}
?>
-
May 30th, 2002, 12:05 PM
#6
Thread Starter
Fanatic Member
that didnt work
-
May 30th, 2002, 12:07 PM
#7
Stuck in the 80s
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>';
}
?>
-
May 30th, 2002, 12:08 PM
#8
Stuck in the 80s
-
May 30th, 2002, 12:14 PM
#9
Thread Starter
Fanatic Member
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
-
May 30th, 2002, 12:15 PM
#10
Stuck in the 80s
-
May 30th, 2002, 12:16 PM
#11
Thread Starter
Fanatic Member
yep, now i have a universal contact form/anything you want form
-
May 31st, 2002, 07:37 AM
#12
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.
-
May 31st, 2002, 10:40 AM
#13
Stuck in the 80s
Same thing for ACTION, Hobo.
PHP Code:
if ($_POST['action'] == 'show') {
OKAY?
-
May 31st, 2002, 10:42 AM
#14
Thread Starter
Fanatic Member
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.
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
-
May 31st, 2002, 10:46 AM
#15
Stuck in the 80s
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
Yes, starting in 4.2, it will be turned off by default.
Matt:That post was directed at myself. Not you.
-
May 31st, 2002, 10:46 AM
#16
Thread Starter
Fanatic Member
oh okay 
Will the option to turn them on still be existant or is it forcing them to be off?
-
May 31st, 2002, 10:49 AM
#17
you can still turn them on, but it is not recommended for security and speed issues.
-
May 31st, 2002, 10:50 AM
#18
Stuck in the 80s
I've grown to love the superglobals anyways
-
May 31st, 2002, 10:51 AM
#19
Thread Starter
Fanatic Member
damn, i now have to rewrite about 40 pages of code
-
May 31st, 2002, 10:53 AM
#20
Thread Starter
Fanatic Member
wait maybe not, is there any way to force globals on at runtime?
-
May 31st, 2002, 10:58 AM
#21
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.
-
May 31st, 2002, 11:00 AM
#22
Stuck in the 80s
You could mimic it by using the code I gave you below:
PHP Code:
<?php
while (list ($name, $value) = each ($_POST)) {
//something
}
?>
Okay, I can't remember how to do it. I'll get back to you.
-
May 31st, 2002, 11:43 AM
#23
Thread Starter
Fanatic Member
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
-
May 31st, 2002, 11:46 AM
#24
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.
-
May 31st, 2002, 11:48 AM
#25
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|