twig custom form – double verification
-
Hi,
I am using 2 custom twig forms on a page. In both forms I am using
{% if form.submission and form.status %}
to display success or error messages.
The issue is that when I am submitting one form I have verification from both forms appearing.Is there a way to avoid this form confusion?
Thanks
The page I need help with: [log in to see the link]
-
Hi @thepiweb
can you provide the twig snippets for both forms and the code displaying the message(s)?
Thanks
GeorgeHi George,
The first form is placed on page content like this:
{% form entity="mds_registrationcontact" mode="create" %} {% if form.submission and form.status %} <div class="row"> <div class="col-12"> <div class="alert alert-success">{{ form.parameters.messages.success ?? "Ευχαριστο?με για την εγγραφ? σα?" }}</div> </div> </div> {% elseif form.submission and (not form.status) %} <div class="row"> <div class="col-12"> <div class="alert alert-danger">{% if form.parameters.messages.error %} {{ form.parameters.messages.error }} {% else %} {% for descriptor, message in form.errors %} <div>{{ descriptor }}: {{ message|join(', ') }}</div> {% endfor %} {% endif %} </div> </div> </div> {% endif %} <form method="POST" data-toggle="validator"> <fieldset> <div class="form-group"> {% set loc= eventlocations.results.entities[0].mds_location %} <input class="form-control" type="text" name="mds_eventlocationtext" value="{{loc}}" readonly /> </div> <div class="form-group"> <div class="select-wrap" id="mds_eventtitle"> <select name="mds_eventtitletext"> <option value="">-- Seminar Title --</option> {% for eventtitle in eventtitles.results.entities %} <option value="{{eventtitle.mds_title}}">{{eventtitle.mds_title}}</option> {% endfor %} </select> </div> </div> <div class="form-group"> <div class="select-wrap" id="mds_event"> <select name="mds_eventfulltitletext"> <option value="">-- Event --</option> {% for eventfulltitle in eventfulltitles.results.entities if eventfulltitle.mds_location == loc %} <option value="{{eventfulltitle.mds_eventtitle}}" data-sem="{{eventfulltitle.mds_eventtitlelookup}}">{{eventfulltitle.mds_eventdate}}</option> {% endfor %} </select> </div> </div> <div class="form-group"> <input class="form-control" name="mds_lastname" pattern="^[A-Za-zα-ωΑ-Ω????????????????\\s]*$" required="" type="text" placeholder="?νομα:" data-required-error="Το πεδ?ο ε?ναι απαρα?τητο" data-pattern-error="To πεδ?ο δ?χεται μ?νο χαρακτ?ρε? και το κεν?" /> <div class="help-block with-errors"></div> </div> <button class="btn btn-default" type="submit">Εγγραφ?</button> </fieldset> </form> {% endform %}
and the second is placed on the footer with a widget text like this:
<div class="footer-newsletter">[msdyncrm_twig] {% form entity="lead" mode="create" language=1032 %} {% if form.submission and form.status %} <div class="row"> <div class="col-12"> <div class="alert alert-success">{{ form.parameters.messages.success ?? "Ευχαριστο?με για την εγγραφ? σα? στο Newsletter" }}</div> </div> </div> {% elseif form.submission and (not form.status) %} <div class="row"> <div class="col-12"> <div class="alert alert-danger">{% if form.parameters.messages.error %} {{ form.parameters.messages.error }} {% else %} {% for descriptor, message in form.errors %} <div>{{ descriptor }}: {{ message|join(', ') }}</div> {% endfor %} {% endif %} </div> </div> </div> {% endif %} <form class="form-inline" method="POST" data-toggle="validator"> <fieldset> <div class="form-group"> <input class="form-control" name="firstname" pattern="^[A-Za-zα-ωΑ-Ω????????????????\\s]*$" required="" type="text" placeholder="?νομα:" data-required-error="Το πεδ?ο ε?ναι απαρα?τητο" data-pattern-error="To πεδ?ο δ?χεται μ?νο χαρακτ?ρε? και το κεν?" /> <div class="help-block with-errors"></div> </div> <div class="form-group"> <input class="form-control" name="lastname" pattern="^[A-Za-zα-ωΑ-Ω????????????????]*$" required="" type="text" placeholder="Επ?θετο:" data-required-error="Το πεδ?ο ε?ναι απαρα?τητο" data-pattern-error="To πεδ?ο δ?χεται μ?νο χαρακτ?ρε?" /> <div class="help-block with-errors"></div> </div> <div class="form-group"> <input class="form-control" name="emailaddress1" required="" type="email" placeholder="Email:" data-required-error="Το πεδ?ο ε?ναι απαρα?τητο" data-error="Μη ?γκυρο email" /> <div class="help-block with-errors"></div> </div> <button class="btn btn-default" type="submit">Εγγραφ?</button></fieldset> </form>{% endform %} [/msdyncrm_twig] </div>
On the first one I’ve only included the form code and not the whole twig tag because of the existence of many fetchxml snippets.
Thanks
Hi @thepiweb
The forms were not really designed to support a scenario with 2+ forms on a page.
However we can add a way for the system to distinguish submissions from different forms, either automatically or manually.
Thanks
Hi @wizardist
We have the newsletter registration on the footer so if we could distinguish the submissions that would be greatly appreciated.
Is there something I can do with the code or should we wait for an update on the plugin?
Thanks
Hi @thepiweb
You can upgrade to 1.2.19 and have two or more forms on one page.
See the updated docs on custom forms: https://docs.alexacrm.com/wpcrm/twig/#displaying-custom-forms
Just don’t forget to add different “key” attributes to form tags.
Thanks
Thanks @wizardist,
This was very helpful and resolved the issue.
Although I was a little confused with the documentation.
{{form.id}} didn’t return anything and the forms weren’t being submitted.
I used {{form.key}} instead and it worked fine.Thanks again
- The topic ‘twig custom form – double verification’ is closed to new replies.