0

I have long list of products and in each product i have form:

<form action="index.php" method="post">
    <input type="hidden" name="prodid" value="<?= $id ?>" />
    ...
</form>

I want to jump to product on call action like:

<a href="#prodid<?= $id ?>">jump to product</a>
...

<a name="prodid<?= $id ?>"></a>

but i must use post method. In get method I would use this:

<form action="index.php#prodid<?= $id ?>" method="get">
    ...
</form>

How to do it?

Nips
  • 13,162
  • 23
  • 65
  • 103
  • the technique is the same, it only depends on getting the variables via either GET or POST... I don't understant where's the problem? – jackJoe Oct 19 '11 at 10:02

6 Answers6

5

Using <a name="..."></a> for a jump-mark is deprecated in HTML5 as the a-element has no name-attribute anymore. See here: HTML Anchors with 'name' or 'id'? and in the specs.

You can jump to anything on the site with a specified id-attribute by adding the #[id] to the URL (or creating a link like <a href="#[id]">jump</a>).

Adding the hashtag does not have anything to do with GET or POST. It's just a Browser-Feature.

Community
  • 1
  • 1
Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
  • name is only deprecated in xhtml, it's still valid in html. See http://derickrethans.nl/html-name-attribute-deprecated.html and http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id. – Steve Oct 19 '11 at 10:06
  • @Steve Its not, there is no `name`-attribute in HTML5 – Lukas Knuth Oct 19 '11 at 10:09
1

What about simple:

<form action="index.php#prodid<?= $id ?>" method="post">
    <input type="hidden" name="prodid" value="<?= $id ?>" />
    ...
</form>

You will use both - hidden input and anchor in action.

hsz
  • 148,279
  • 62
  • 259
  • 315
0

I would think that you can still use #prodid=x syntax even with "post" methods. POST method only controls how the data is sent to the server.

When the browser displays the target page of the form, it will see the #anchor and scroll the page accordingly. Moreover, you can submit the form without the tag and then inside your processing script have something like this:

// process everything as required
...
header("location: mypage.php#prodid=$prodid");
Aleks G
  • 56,435
  • 29
  • 168
  • 265
0

Use the following syntax to create a bookmark on the page for each product:

<a name="prodid<?= $id ?>">
    <form action="index.php" method="post">
        <input type="hidden" name="prodid" value="<?= $id ?>" />
        ...
    </form>
</a>

If you are writing xhtml/html5 drop the name attribute then you can use:

<form action="index.php" method="post" id="prodid<?= $id ?>">
    <input type="hidden" name="prodid" value="<?= $id ?>" />
    ...
</form>
Steve
  • 1,440
  • 13
  • 13
0

but i must use post method.

No, you don't need that.
GET method is all right.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

For a long list of similar items, the way I use the most is an interator and a prefix. It gives me a context in which every items are ordered and each one can be jumped to with : <a href="#section24">Additionnal information</a>

Frederik.L
  • 5,522
  • 2
  • 29
  • 41