Add custom button in form

16 views
Skip to first unread message

Mahantesh U

unread,
Oct 23, 2013, 10:41:18 AM10/23/13
to django...@googlegroups.com
Hi All,

in views.py:
----------------------

   def post_form_values(request):
    if request.method == 'POST':
        form = facultyForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse("Form data saved to database")
            #return HttpResponseRedirect('/draft/')

    else:
        form = facultyForm()

    return render_to_response('base.html', { 'form': form }, context_instance=RequestContext(request))


in base.html:
---------------------------------
 <form action="" method="POST">
{% csrf_token %}
            {{ form.as_p }}
        <input type="submit" value="post" />
        </form>


Here it will generate few fields like:

name: [textbox] i mean <input type=text /> -
url: [textbox] i mean <input type=text /> -
city: [textbox] i mean <input type=text /> -

-----
----
--- etc


My question is: I want to add the button  after url field. Once the user clicks on button I will use the entered url value and extract the details what i want... Please let me know how to add custom button to the form.

------------------------------------

Thanks
Mahantesh



Augusto Destrero

unread,
Oct 23, 2013, 11:34:48 AM10/23/13
to django...@googlegroups.com

On Wednesday, October 23, 2013 4:41:18 PM UTC+2, Mahantesh U wrote:
My question is: I want to add the button  after url field. Once the user clicks on button I will use the entered url value and extract the details what i want... Please let me know how to add custom button to the form.


Can you use javascript/jquery for this? Something like:

$('input[name=url]').after('<button id="btn_after_url">Click me</button>');
Reply all
Reply to author
Forward
0 new messages