1

I ran into a trouble yesterday and I don't know how to fix this problem. I have a form

<form action="#" method="POST" target="_self">
<input type="text" name="name">
<input type="Submit" value="submit">
</form>

and the .php code is simple: < ?php if (isset($_POST['name'])) echo $_POST['name']; ? >

the problem is that after I write something in the "name" field and click "submit" all I get is " Notice: Undefined variable: n in G:\wamp\www......" ...but, if i change to action="somefile.php" I get the result I need... it works...

Do you what the problem may be?

  • 2
    `#` means go to top of the page without refreshing, so your form will not submit for sure, if you want to submit to the same page use `action=""` – CodeBird Mar 06 '14 at 18:39
  • I read on this site that action="" is dangerous and should not be used. Is this correct ? – Vali Ploiesti Mar 06 '14 at 18:43
  • someone who wrote it has no clue – Your Common Sense Mar 06 '14 at 18:44
  • @ValiPloiesti: Read [Difference between action=“” and action=“#” in HTML](http://stackoverflow.com/questions/20720375/difference-between-action-and-action-in-html) and the link in the accepted answer. – Amal Murali Mar 06 '14 at 18:45
  • @ValiPloiesti it has nothing to do with dangerous, `action=""` is same as `action="something.php"` don't believe everything you read, do some research... Some people have no clue as `Your Common Sense` said – CodeBird Mar 06 '14 at 18:53

3 Answers3

2

You can either change the action to

action=""

or remove it entirely, which will default to posting to the same page.

larsAnders
  • 3,813
  • 1
  • 15
  • 19
0

action="your_page.php"

your_page.php is where to send the form-data when the form is submitted.

Possible values: An absolute URL - points to another web site (like action="http://www.example.com/example.htm") A relative URL - points to a file within a web site (like action="example.htm")

Zarkoeleto
  • 133
  • 1
  • 2
  • 5
0

Why do you want to send something to "#"? If send something to the same page, I prefer use action="<?php echo $_SERVER['PHP_SELF']; ?>", in additional if you want send something to the same page without refreshing, try using AJAX.

VVLeon
  • 399
  • 3
  • 8