Form Saving Related Issues

7 views
Skip to first unread message

pradam programming

unread,
Oct 31, 2016, 7:01:33 AM10/31/16
to django...@googlegroups.com
Hi,
Please I need an advice on the best approach to take on the following issues.
I have create a form to save user details like first name,last name,email,mobile number etc...

1.Now I need to show error message (In Models i gave email and mobile no field as unique = True) when user enter a email id if email id exists in database show message like email id exists beside the email text field(also for  the mobile no) else proceed with form.
2.After i saving the form i need to show alert of success.

regards,
Pradam Abhilash

Andromeda Yelton

unread,
Oct 31, 2016, 2:35:58 PM10/31/16
to django...@googlegroups.com
If your model has the uniqueness constraint, you should get a form error message automatically. If you don't want your model to have that constraint but you still want your form to throw an error message, you can add a clean_<name of email field> and a clean_<name of mobile field> function that check for uniqueness and raise ValidationError if it fails (see examples here: https://docs.djangoproject.com/en/1.10/ref/forms/validation/ ).

When the form saves successfully, the user will be redirected to the success_url you provide. That template can have success message text. Alternately, in your form_valid function in the view, you could add a success message that will get added to whatever page you're redirecting to (as long as you make sure your template is rendering messages) -> https://docs.djangoproject.com/en/1.10/ref/contrib/messages/#adding-a-message

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGGVXBOz6kQs%2BHhR%2BsrTUApOGnR7t50HHQuvSN_zJz6VMQosFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Andromeda Yelton
Vice President/President-Elect, Library & Information Technology Association: http://www.lita.org

pradam programming

unread,
Oct 31, 2016, 10:31:00 PM10/31/16
to django...@googlegroups.com

Thank you sir for the reply..
But I am using HTML forms then what should I do...?  I want error message should display instantly when user enter existing mail id..!


ludovic coues

unread,
Nov 1, 2016, 5:46:05 AM11/1/16
to django...@googlegroups.com
You need some kind of ajax.
Once the user have entered their email, send a request to your django
app with only that email. Django check if the email exist and send a
reply with yes or no.
>>> email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAGGVXBOz6kQs%2BHhR%2BsrTUApOGnR7t50HHQuvSN_zJz6VMQosFw%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> Andromeda Yelton
>> Vice President/President-Elect, Library & Information Technology
>> Association: http://www.lita.org
>> http://andromedayelton.com
>> @ThatAndromeda
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFE1XCbVpkpOboCKR_Xck-oTm2NJYCVQ6ssWZsBWRaNe3pQM9Q%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGGVXBPwq%2BGaEkfFYRx%3Df3uL3Wzbh1xn5BLKdC7%2BCp_PHapBtQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

pradam programming

unread,
Nov 1, 2016, 5:48:10 AM11/1/16
to django...@googlegroups.com

Hi Sir,
Thank you. ! It's really help full.. Will try to do it



>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAGGVXBOz6kQs%2BHhR%2BsrTUApOGnR7t50HHQuvSN_zJz6VMQosFw%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> Andromeda Yelton
>> Vice President/President-Elect, Library & Information Technology
>> Association: http://www.lita.org
>> http://andromedayelton.com
>> @ThatAndromeda
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFE1XCbVpkpOboCKR_Xck-oTm2NJYCVQ6ssWZsBWRaNe3pQM9Q%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGGVXBPwq%2BGaEkfFYRx%3Df3uL3Wzbh1xn5BLKdC7%2BCp_PHapBtQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages