POST with link without forms
I don't know if this is possible, but I want to submit information using POST with a link. I know I can use GET, and I know I can use a form with a hidden value and submit it with a link, but I don't want either of those. I need to be able to do something like
<a href="mysite.com/submit.php" target="_BLANK" value="$id">Submit</a>
Also, doing it without JS would be nice. :)
Is this possible? Thanks.
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
Few ways to do it, but I suggest using a CSS on the submit button (to keep it all semantic) or you could do a js submit on link click.
href="javascript: sendform();"
Your function then:
<script>function sendform(){ document.formName.submit(); }</script>
Obviously, change formName to the name attribute of your form.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
Did I deserve the downvote? :)
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
@migcosta: No, I'm not trying to hack. :) I'm trying to allow subscribers for my email newsletter to click on a link which takes them to a web version of the email. Rather than use GET, (e.g. mysite.com/web-version.php?emailId=3) I'd like to use POST (e.g. mysite.com/web-version.php). I tried using a form with a hidden input with the email id as the value and then submit the form with a link, but it alerts the user saying that you're about to submit an unsecured form. So, that's why I posted this question. :)
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
:) I see.. you can do it like this..
use a htacess redirect
email link : mysite.com/web-version/jun/
and the htacess would redirect the request to mysite.com/web-version.php
and on the php file you can detect what is in front of the expression "web-version" (in the url) and then you will have your id (jun = 3 or what ever :) )...
this way you wont have to deal with forms and you can over pass the emails limitations..
:)
I see... Do you know of any sample scripts? I'm just starting PHP now, and I'm having some trouble. :)
Also, does that show the email on my-site.com/web-version.php or my-site.com/web-version.php?id=3? I need the first one. :)
Thanks!
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
If you go down this route, you'll need a mod_rewrite
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^emailid=(.*)$ [NC]
RewriteRule ^(.*)$ /email/$1/%1? [R=301,L,NE]
I haven't tried it though. Hmm, I'm not the sharpest tool in the box when it comes to regex.
When uploading .htaccess files, you may get a problem. You can upload (FTP) it as htaccess.txt then rename it to .htaccess once on the server.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Nice on ardav :)
But I will recommend calebcook to start with one other thing in mind..
calebcook this will be very helpful if you intend to develop web sites...
Do you know what is a SEF? (search engine friendly urls) if not.. google it..
You can use the SEF structure to build your email links (its cleaner and nice looking) :)
please read carefully the above links they have examples and code
http://www.akchauhan.com/create-search-engine-friendlysef-websites-in-php-using-url-rewriting/
http://www.techtalkz.com/programming/180-php-sef-urls.html
I hope that helps :)
Thanks for all your help! :)
I guess I can use that, but I wanted to have the id POST to my-site.com/web-version.php so that any email could be viewed there, but only from a link in the email. Because if I use GET, the user could go from my-site.com/web-version.php?id=3 to my-site.com/web-version.php?id=5 or something and get an email that wasn't intended for them. It would be nice if the link posts the id so that it's a little more secure. Thanks for your help!
Caleb
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
One thing I did is made it so that it'll also have the email in the url (my-site.com/web-version.php?id=1&email=me@example.com). It'll check to see if the email is in the database, and then let them view the email if it is. I suppose I could do letters as well, or add another field, such as the first name to make it better, but I'm thinking that'd be kinda' crazy. :)
Thanks for all the help!
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4
Check that the '@' is urlencoded to '%40' when you looka the html.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
:) I see.. you can do it like this..
use a htacess redirect
email link : mysite.com/web-version/jun/
and the htacess would redirect the request to mysite.com/web-version.php
and on the php file you can detect what is in front of the expression "web-version" (in the url) and then you will have your id (jun = 3 or what ever :) )...
this way you wont have to deal with forms and you can over pass the emails limitations..
:)
That works-Thanks!
calebcook
Junior Poster in Training
66 posts since Jun 2011
Reputation Points: 10
Solved Threads: 4