How do you use a link as a post request?

1,961 views
Skip to first unread message

leaks

unread,
Mar 3, 2012, 5:21:39 AM3/3/12
to django...@googlegroups.com
How do you use a link as a post request?
this is a thing that I have never done before... maybe use it inside a form?
I searched and didn't find anything similar in django...

Thanks in advance!

Daniel Roseman

unread,
Mar 3, 2012, 6:42:13 AM3/3/12
to django...@googlegroups.com
You can't. A link is a GET, by definition.

It is possible to style a form submit button to look like a link, though. One of my least proud moments in web development is when I had to do this.

Another alternative might be to use Javascript to trigger a form submission when the link is clicked.
--
DR.

bb6xt

unread,
Mar 5, 2012, 3:07:19 PM3/5/12
to Django users
You can achieved that by using javascript or jquery. But personally I
prefer jquery so I'll illustrate with a jquery example.

# in your template

<script type="text/javascript">
funcion submitForm(){
$.ajax({
url: "some url",
type: "POST",
data: $("#myform").serialize(),
success: function(){//do magic}
});
</script>

<form id="myform" action="#" method="whatever">
<input name="whatever" value="iwhlihvkhvj">
<!--more fields, could input/select/radio etc etc-->
<label onClick="">Submit</label>
</form>

Note however that the form is submitted asynchronously ($.ajax())

leaks

unread,
Mar 5, 2012, 3:27:08 PM3/5/12
to django...@googlegroups.com
thanks bb6xt..! I couldn't find an answer so I went with a forms POST request... Thank you anyway... Will give it a try :)

bb6xt

unread,
Mar 5, 2012, 4:27:57 PM3/5/12
to Django users
You're welcome. I missed one detail in my last post. Here is it:
<label onClick="javascript: submitForm()"></label>
Reply all
Reply to author
Forward
0 new messages