Hello,

Emailfield is nothing other then a normal InputField but later with a
special validator. I would take InputField then write your own Validator
where you split input commasparated an validate every address with a regex.

https://stackoverflow.com/questions/3217682/checking-validity-of-email-in-django-python

Regards

Am Do., 15. Apr. 2021 um 22:22 Uhr schrieb Smiley <ungurkris...@gmail.com>:

> Hello,
>
> I have another problem.
>
> I am trying to get CC to accept multiple email addresses but I do not seem
> to get it to work as it always says *Enter a valid email address*. I've
> searched for solutions, heard the new field *MultiValueField* but I also
> do not know how to use this in *forms.py*.
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> This is my *forms.py* code:
>
> from django import forms
> #  from django.forms.fields import MultiValueField
> from django.forms.widgets import EmailInput, TextInput
>
>
> class ComposeForm(forms.Form):
>     email_to = forms.EmailField(label="To", widget=EmailInput(attrs
> ={"size": 76}))
>     email_cc = forms.EmailField(
>         label="CC",
>         required=False,
>         widget=EmailInput(attrs={"size": 76, "multiple": True}),
>     )
>     email_subject = forms.CharField(
>         required=False, widget=TextInput(attrs
> ={"placeholder": "Subject", "size": 76})
>     )
>     email_message = forms.CharField(
>         required=True, label="", widget=forms.Textarea(attrs
> ={"rows": 19, "cols": 78})
>     )
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> And this is my *views.py* code:
>
> from django.shortcuts import render
>
> from .forms import ComposeForm
>
>
> def email_template(request):
>     if request.method == "GET":
>         form = ComposeForm()
>     else:
>         form = ComposeForm(request.POST)
>         if form.is_valid():
>             print(form)
>             email_to = form.cleaned_data["email_to"]
>             email_cc = form.cleaned_data["email_cc"]
>             email_subject = form.cleaned_data["email_subject"]
>             email_message = form.cleaned_data["email_message"]
>
>             print("Emails:", email_cc)
>         else:
>             print("DEBUG:", form.errors)
>     return render(request, "email_template.html", {"form": form})
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> And this is my *email_template.html* HTML:
>
> <!DOCTYPE html>
> <html lang="en">
> <head>
>     <meta charset="UTF-8">
>     <meta http-equiv="X-UA-Compatible" content="IE=edge">
>     <meta name="viewport" content="width=device-width, initial-scale=1.0">
>     <title>Home</title>
> </head>
> <body>
>     <form method="POST">
>         {% csrf_token %}
>         <table>
>             {{ form.as_table }}
>         </table>
>         <input type="submit" value="Submit">
>     </form>
> </body>
> </html>
>
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Please tell me whether it's possible to have multiple email addresses in
> *email_cc* aka *CC* field in Django or do I have to use frontend
> frameworks for this one job or start using one for better practice (get
> used to using frameworks to build frontend side)?
>
> Please advise.
>
> Regards,
> Kristen
>
> sebasti...@gmail.com kirjutas teisipäev, 23. märts 2021 kl 22:24:01 UTC+2:
>
>> I have implement it as a bootstrap modal where a Form with fields are
>> shown. When User click submit the Page load New but If you don't want that
>> Page is load New you need a Ajax jquery submit to django
>>
>> Kristen <ungurk...@gmail.com> schrieb am Mo., 22. März 2021, 15:46:
>>
>>> Hello,
>>>
>>> Correct. I want to the user to click a button and have a form appear
>>> where the user can compose an email.
>>>
>>> Gmail uses javascript to render their form on top of the inbox because
>>>> they don't want you to have to leave the inbox page. You probably don't
>>>> have that requirement.
>>>>
>>>> Let me know if that works for you.
>>>>
>>>
>>> I don't really want to redirect the user elsewhere. I would really like
>>> to do the Gmail way because I like it and thought maybe it's possible with
>>> Django.
>>>
>>> Nonetheless, I will try out your idea because my curiosity wants to know
>>> whether it's worth the effort to do it the Gmail way or go easier route way
>>> by doing it just as you explained.
>>>
>>> Let me know what you think of it, the Gmail way idea.
>>>
>>> Kind regards
>>>
>>>> --
>>>
>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CADGe-3u6cCMfZ-s2BfmntXK6WMGh7AYO%3D%2BBk7KJyCGJycSp1pw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CADGe-3u6cCMfZ-s2BfmntXK6WMGh7AYO%3D%2BBk7KJyCGJycSp1pw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0ca61efa-8033-4e4b-9fa0-7b5805b6cc43n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0ca61efa-8033-4e4b-9fa0-7b5805b6cc43n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mw40kekQ9VDT9ZueNzz02DfS-6okYrZS-8dMLvZ7FaVsg%40mail.gmail.com.

Reply via email to