Passing values to next page using anchor tag

15,175

Solution 1

You said that you don't want anything in the url to be shown except from page name so why not using a form with psot method? Post will not show anything in the browser and you won't have to deal with sessions/cookies which require more work.

From documentation

  • POST requests are never cached
  • POST requests do not remain in the browser history
  • POST requests cannot be bookmarked
  • POST requests have no restrictions on data length
<form method="post" action="index1.php">
  <input type="hidden" name="name" value="username" />
  <input type="hidden" name="username" value="123" />
  <input type="submit" name="submit" value="submit" /> 
</form>

Now in your second page you just need to retrieve data you need throw variable $_POST['name'] and $_POST['username']. You can also make your submit button look like a link with some css.

Solution 2

You can use the session variable to pass the value from one page to another page.

Share:
15,175
user3350885
Author by

user3350885

Updated on June 04, 2022

Comments

  • user3350885
    user3350885 almost 2 years

    One quick question -

    I have an anchor tag which on clicking opens a new target window.

    I don't want to pass the values either in post or get method.

    my html code is like this.

        <a class="employee_details" target="_blank" href="index1.php?name=username&id=123">UserName</a>
    

    Is there a way to pass the values to the next page using jquery in a hidden type since there is no submit button. In other words, clicking the anchor tag will redirect to another one page where i should get the name and id and that part should NOT BE VISIBLE ANYWHERE in the url.

    Any help Kimz

  • AO_
    AO_ about 10 years
    You should keep the anchor outside of the form in this case to preserve inline-display..
  • Rohit Awasthi
    Rohit Awasthi about 10 years
    inline-display means?
  • AO_
    AO_ about 10 years
    Form is a display:block element which will force the other elements around the anchor to not share the line it sits on..... e.g. w3schools.com/cssref/…