I want to send a link for some people:
http://www.example.com/form/ ?q=example@me.com
If they click on the link, it will go to the page / form / where is the form with several fields.
I would like to pre-populate it with this q line, which would fill this email input
with the specified email address in the string " example@me.com ".
The website is made in Django, I would like to ask what is the best approach to achieve this.
Should I use JS, jQuery, Django? I don’t know where to start.
I would like something like this:
http://support.unbounce.com/entries/307658-Can-I-pre-populate-a-form-with-URL-parameters-VIDEO-
but on my site. Can someone help with a simple form and example?
thanks
models.py
from django.db import models class Example(models.Model): username = models.CharField(max_length=200, blank=True) email = models.CharField(max_length=200) image = models.ImageField(upload_to='profiles', blank=True) text = models.CharField(max_length=200, blank=True)
forms.py
from django import forms from models import Example class ExampleForm(forms.ModelForm): class Meta: model = Example
views.py
from django import forms from models import Example from forms import ExampleForm from django.template import RequestContext, Context from django.core.context_processors import csrf from django.shortcuts import render_to_response from django.shortcuts import render_to_response, get_object_or_404 from django import http import os import json from django.http import HttpResponse from django.http import HttpResponseRedirect from django.conf import settings def index(request): if request.method == "POST": form = ExampleForm(request.POST, request.FILES) if form.is_valid(): form.save() return http.HttpResponseRedirect('/success/') else: form = ExampleForm() return render_to_response('index.html', {'title': 'Example Form', 'form': form},context_instance=RequestContext(request))
urls.py
from django.conf.urls import patterns, include, url from django.conf import settings from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'signup.views.index', name='index'), url(r'^admin/', include(admin.site.urls)), )
index pattern
<form id='add_cat' method='post' enctype="multipart/form-data">{% csrf_token %} <input id="id_username" maxlength="200" name="username" type="text" placeholder="username"> <input id="id_email" maxlength="200" name="email" type="text" > <input id="id_picture" maxlength="200" name="picture" type="text"> <textarea id="id_text" row="3" name="first_text" placeholder="Type something…"></textarea> <input id="add_cat_btn" type='submit' value="save"> </form>