Reputation: 17
I am trying to pass an id from a button in page1 to a variable that's in php in page2. The id is dynamic because there will be multiple buttons and i only need to send the clicked button id. The problem is I don't know where to start really. Do I need to use cookies? I have read some people use sessions but that is a bit overkill I think.
This is the button in page1
<td class="button-table">
<button class="leads-more-info-btn"
id="<?php echo $leadKey = $allIssues->key ?>"
onclick="sendData(this.id)">Apply..
</button>
</td>
As you can see i tried using the onclick
, but that is in javascript. I would like to do it in php.
And the variable name in Page2 is called $currentLead
. So to summarize page1:buttonID->page2:$currentLead
.
Upvotes: 0
Views: 303
Reputation: 66
You can definitely use $_SESSION
as has been mentioned, but I'm fairly sure that you could also refactor your page so that your buttons are either contained in a <form>
, or use AJAX to do a $.get()
or $.post()
to the other page's URL when the button is clicked. You could then check $_GET
or $_POST
to find/retrieve the values in that page.
A hyperlink to the new page (instead of a button) would work as well. You could simply pass the id in the querystring at that point, and could even style the hyperlinks to look like buttons with CSS if you want to keep the look/feel of a button.
Upvotes: 3
Reputation: 145
Store it in a $_SESSION, Then use header() function if you want to get redirected to page2
Upvotes: -1