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

Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work?

P: n/a
look at this :
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action="test1.php" method="POST" id="form" >
<input type="text" id="tt" />
<input type="submit" value="submit" id="submit" />
</form>
</body>
</html>

I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.
Jun 14 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

--
http://www.mgogala.com

Jun 14 '06 #2

P: n/a
C.
Hi,

Let's try this :

<input type='text' name='tt' value=''>

instead of your <input type='text' ...> line.
C.
Carl Anatorian wrote:
look at this :
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action="test1.php" method="POST" id="form" >
<input type="text" id="tt" />
<input type="submit" value="submit" id="submit" />
</form>
</body>
</html>

I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.

Jun 14 '06 #3

P: n/a
Mladen Gogala wrote :
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

thank you very much !!!!!!
But why does php only pick "name" attribute?
Jun 14 '06 #4

P: n/a
Mladen Gogala 写道:
On Wed, 14 Jun 2006 21:09:17 +0800, Carl Anatorian wrote:
I want to it to show the text I enter in the input when I press the
'submit' botton.But it doesn't work.


Because PHP picks "name" attribute, not "id" attribute. Try with this:
<html>
<body>
<?php
if(isset($_POST['tt'])) {
echo $_POST['tt']."<br/><br/><br/>";
}
?>
<form action=<?=$_SERVER['PHP_SELF']?> method="POST" >
<input type="text" name="tt" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html

Another one :
<?php
if($_COOKIE['hello'] != "world") {
$result = setcookie("hello","world",60*10);
}
?>
<html>
<body> <?php
if(isset($_COOKIE['hello'])) {
echo "hello !";
}
?>
</body>
</html>

I think it will show "hello !" when I access it the second time, but it
never.Why? I don't disable my browser's cookies.
Jun 14 '06 #5

P: n/a
Carl Anatorian wrote:
But why does php only pick "name" attribute?


ID's not name, and it won't be sent along with the request, so it's not
the problem for PHP.
It's true that the new XHTML stop using name and use id instead, but
name still be used in inputs, textareas, and buttons.

Jun 14 '06 #6

P: n/a
Carl Anatorian schrieb:
[...]
Because PHP picks "name" attribute, not "id" attribute. Try with this: [...]

thank you very much !!!!!!
But why does php only pick "name" attribute?


These attributes have quite different meanings: name is for the key of
form submissions, while id is for DOM access, and has more restrictive
naming rules, and must be unique. These restrictions are not applicable
for the name attribute. These are valid:

<input type="radio" name="option" value="0">
<input type="radio" name="option" value="1">

<input type="checkbox" name="choice[]" value="0">
<input type="checkbox" name="choice[]" value="1">

<input type="text" name="friends[]" value="Tina">
<input type="text" name="friends[]" value="Ike">

While they all would cause validation errors if id was used instead of
name. Also stuff like getElementById("option") would not work if id was
not unique.

--
Markus
Jun 14 '06 #7

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carl Anatorian wrote:
But why does php only pick "name" attribute?


It's not PHP, it's HTML. Geez, read the specs:

http://www.w3.org/TR/html4/interact/forms.html#h-17.2

When a form is submitted for processing, some controls have their name
paired with their current value and these pairs are submitted with the
form. Those controls for which name/value pairs are submitted are called
successful controls.

- --
- ----------------------------------
Ivn Snchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Now listening to: Yuki Kajiura - Madlax Original Soundtrack 2 (2004) - [4]
Fall on you (2:13) (91%)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEkBJY3jcQ2mg3Pc8RAhIXAJ9rOpfYq668/QCskdyqr61oMoOPeQCfV8Ll
XufBSAoPsPB800yktLISNs0=
=wqT8
-----END PGP SIGNATURE-----
Jun 14 '06 #8

P: n/a

Carl Anatorian wrote:
Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work?


The title for your post is probably not very descriptive. A better one
would be "Form doesn't work" or something like that. Luckily, because
of the nice people in the comp.lang.php group, you get away with it.

Jun 14 '06 #9

P: n/a
Carl Anatorian wrote:
Another one :
<?php
if($_COOKIE['hello'] != "world") {
$result = setcookie("hello","world",60*10);
}
?>
<html>
<body> <?php
if(isset($_COOKIE['hello'])) {
echo "hello !";
}
?>
</body>
</html>

I think it will show "hello !" when I access it the second time, but it
never.Why? I don't disable my browser's cookies.


Carl, setcookie returns boolean, so it would be prudent to check
whether it has actually happened. You should add something like:
if (!$result) { die("Better luck next time"); }
Second, cookies will NOT be sent if the HTML headers have already been
sent. Your heading (<html>) makes sure that they have been sent, so your
cookie will probably not be sent. You should do something like
<?php ob_start(); ?> before the HTML header.

--
Mladen Gogala
http://www.mgogala.com
Jun 14 '06 #10

P: n/a
Carl Anatorian wrote:
thank you very much !!!!!!
But why does php only pick "name" attribute?


I'll give you the answer from the movie "Who Framed Roger Rabbit": It
was drawn that way.

--
Mladen Gogala
http://www.mgogala.com
Jun 14 '06 #11

P: n/a
"the DtTvB" <me********@gmail.com> wrote in message
news:11*********************@f6g2000cwb.googlegrou ps.com...
Carl Anatorian wrote:
But why does php only pick "name" attribute?


ID's not name, and it won't be sent along with the request, so it's not
the problem for PHP.
It's true that the new XHTML stop using name and use id instead, but
name still be used in inputs, textareas, and buttons.

That's actually quite insane, if you think about radio buttons. more than
one elements may share the same name while their id's must be distinct. Now
if you have a radiobutton group like so:

<input type="radio" name="foo" id="foo_1" value="1">
<input type="radio" name="foo" id="foo_2" value="2">
<input type="radio" name="foo" id="foo_3" value="3">

Traditionally the name is submitted, so in the backend you just check the
value of form-variable named foo and you know what was selected. Now if you
send id instead of name, first you need to go through all the id's to see
which is set, then get the value of it. To me this makes no sense. The name
binds the control group together while the id distincts individual controls.

What's the point again fixing something that isn't broken? Actually breaking
something that works perfectly. I've always thought it like this: id is for
client-side, name is for server side. The id is used with javascripts, like
getElementById when accessing a certain control and binding lables to
controls. The name is what the server side should see, clear and simple.

So what's this new XHTML that is going to destroy a perfectly working
system?

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 15 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.