POSTing using a seemingly normal link
Recently, when I was developing a PHP facebook application, I came across the need to use a POST form, but I didn’t want the form to show up as a form, with a submit button and such (because all the inputs would be hidden.)
Therefore, I came up with this little trick…
<form action="script.php"> <input type="hidden" name="uid" value="<?php echo $uid; ?>" /> <input type="hidden" name="pref" value="go" /> <input type="hidden" name="action" value="<?php echo $action ?>" /> <input type="hidden" name="sess" value="<?php echo $sesskey; ?>" /> <input type="submit" id="send" class="hide" style="display:none;" name="submit" value="<?php echo $etag; /* Why not? */ ?>" /> <label for="send" class="link">Click me to Print!</label> </form>
Here, I just hide the submit button, and use a styled label as the target to the hidden submit button.
This way it doesn’t get in the way of the user, and I can ensure their session isn’t duplicated, or a potentially long url is created.
I also personally don’t like the ‘form’ look, so here’s some css to ‘unform’ the looks…
input[type=hidden], .hide { display:none; } /*Firefox Shows Slight Spacing for Hidden Elements (Older versions). */ .link { color:blue; text-decoration:underline; cursor:pointer; } .link:hover { color:orange; }
I recommend this for ‘print’ pages, because you can post as much data as you want, and it can be linked to the user’s session, so the link can’t be shared
That’s all! If anyone wants a good tutorial on how to write a facebook application, from A to Z, please leave a comment!