Zeeshan Rang
Zeeshan Rang

Reputation: 19885

How to pass value to a Html label into php?

I have am trying to pass the value of a label into the php.

how should i do that? My HTML looks like:

<form action='unsubscribe.php' method='get'>
  <label for='[email protected]'>[email protected]</label>
  <input type='submit' value='Unsubscribe me'>
</form>

How can i get the value of this label passed into my unsubscribe.php?

Best Zeeshan

Upvotes: 0

Views: 10483

Answers (3)

danamlund
danamlund

Reputation: 674

By using the <input type="hidden" ... /> tag:

<form action='unsubscribe.php' method='get'>
<input type="hidden" name="email" value="[email protected]" />
<input type='submit' value='Unsubscribe me'>
</form>

If you are going to use <form method="get" ...> you might as well just make a url:

<a href="http://www.example.org/unsubscribe.php?email=zee%40example.org">Unsubscribe</a>

Or with php (note the urlencode):

print("<a href=\"http://www.example.org/unsubscribe.php?email=".urlencode("[email protected]")."\">Unsubscribe</a>");

Upvotes: 4

S Pangborn
S Pangborn

Reputation: 12739

Why not when composing the link for the e-mail, append the e-mail address you're sending it to in the unsubscribe url?

<a href="http://example.com/[email protected]">Unsubscribe Me!</a>

Upvotes: 0

Andrew Hare
Andrew Hare

Reputation: 351526

You will need to create a hidden input, then use JavaScript to populate the hidden input prior to posting the form so that unsubscribe.php can retrieve it via $_POST.

Upvotes: 1

Related Questions