JQuery changing response text from form

First of all, the site is http://emiralmedia.com/site/tennishero , it is simply intended for testing the site before it is launched in a separate domain.

Hi, I want to change the response error from the CRM contact form using stackoverflow help. I managed to integrate it into wordpress. The form is linked with javascript to integrate messages sent from the wordpress site form with another platform. (Customer Relationship Management). Now I have this contact form code:

<div class="main-content">
  <div class="form-mini-container">
    <form FormHash="29074-1vmo1w4eti26ekzhtj8e" action="https://r3.minicrm.ro/Api/Signup" method="post" class="form-mini">
      <div class='form-row'>
        <input name="Contact[1181][LastName]" id="Contact_LastName_1181" language="RO" type="text" placeholder="Name and surname" />
      </div>

      <div class='form-row'>
        <input name="Contact[1181][Phone]" id="Contact_Phone_1181" language="RO" type="text" placeholder="Phone" />
      </div>

      <div class='form-row'>

        <input name="Contact[1181][Email]" id="Contact_Email_1181" language="RO" type="text" placeholder="Email" />
      </div>





      <div id="Response_29074-1vmo1w4eti26ekzhtj8e" style="display: none;" class="Response raspuns"></div>
      <input id="Submit_29074-1vmo1w4eti26ekzhtj8e form-row form-last-row" type="Submit" value="LETΒ΄S GET IN TOUCH" class="button2">
    </form>
  </div>
</div>
Run codeHide result

When I want to send a message with a contact form, and I forgot to add "Name", "Phone" or "Email", sending me a ResponseError in another language, for example:

<span class="ResponseError" style="transition: none; line-height: 0px; border-width: 0px; margin: 0px; padding: 0px; letter-spacing: 0px; font-weight: 400; font-size: 14px;">Name and surname este obligatoriu</span>
Run codeHide result

... CRM. . , javascript. https://r3.minicrm.ro/api/minicrm.js?t=1470730609

script, .

if (window.location.pathname == '/site/tennishero/') {
  jQuery('.Response span').each(function() {
    if (jQuery(this).text() == 'Name and surname este obligatoriu') jQuery(this).text('Name si required');
  });
}
if (window.location.pathname == '/site/tennishero/') {
  jQuery('.Response span').each(function() {
    if (jQuery(this).text() == 'Telefon este obligatoriu') jQuery(this).text('Phone is required');
  });
}
if (window.location.pathname == '/site/tennishero/') {
  jQuery('.Response span').each(function() {
    if (jQuery(this).text() == 'Email este obligatoriu') jQuery(this).text('Email is required');
  });
}
Hide result

? .

+4
1

( )

, /html , innerHTML (js) html() (jquery). ( ), , , , script . CRM script, , , , , onclick , ajax. , script, ( 10 , ).

, , :

, jQuery, jQuery JavaScript sau de html(). cazul de fata, elementul pe care vreti sa il modificati nu apare odata cu toata pagina, ci atunci cand utilizatorul apasa pe un buton si greseste ceva in formular, deci daca veti rula cand se incarca site-ul ceva gen $(".eroare").html("eroare");, elementul "", fiindca el inca nu exista. Din pacate nu puteti nici simula ceva in genul onclick, pentru cazul in care vizitatorul apasa butonul de trimitere, nici nu puteti modifica direct codul CRM si mesajul primit prin ajax, fiindca, din cate am observat, scriptul pentru formular este unul extern, comunica cu serverul (nu am studiat in amanunt). Asadar, o metoda pe care o puteti folosi este aceea de programa codul care modifica textul sa se repete la un anumit interval de timp, iar daca gaseste acel element cu clasa ResponseError (din cate am vazut), sa ii schimbe continutul. Acesta ar trebui sa ruleze foarte des, pentru ca utilizatorului sa nu ii apara mai intai textul original iar apoi sa se schimbe. Codul de mai jos ia toate elementele cu clasa ResponseError si le modifica continutul, o la 10 milisecunde. - fost testat pe pagina dvs.

Script

setInterval(function() {
    var response_errors = document.querySelectorAll('.ResponseError');
    Array.prototype.forEach.call(response_errors, function(elements, index) {
        document.getElementsByClassName("ResponseError")[index].innerHTML="AICI E TEXTUL ERORII";
    });
}, 10);

- , , .

+1

Source: https://habr.com/ru/post/1651047/


All Articles