Buy Now
Sign in

Run a javascript once the form is sent

jitteryjack , September 13 2007, 22:48
J
jitteryjack 6
September 13 2007, 22:48 #2219
Hi I wish to do the following with a single form: the customer can send a message using the contact form, and if he checks a checkbox, than he will be subscribed to our newsletter using SM2 Marketing.

For this I have created this form:
<div class="form_sx">
Nombre:<strong> (*)</strong><br />
<input name="name" type="text" class="text" size="30" id="nombre" />
<br />
E-mail:<strong> (*)</strong><br />
<input name="email" type="text" class="text" size="30" id="email" />
<br />
Asunto:<br />
<select name="subject" class="text" id="asunto">
<option value="requiero mayor información">requiero mayor información</option>
<option value="favor cotizar proyecto">favor cotizar proyecto</option>
<option value="interesado en instalar">interesado en instalar</option>
<option value="otro">otro</option>
</select>
<br />
</div>
<div class="form_dx">


Teléfono/celular:<strong> (*)</strong><br />
<input name="telefono" type="text" class="text" size="30" id="telefono" />
<br />
Ciudad:<strong> (*)</strong><br />
<input name="ciudad" type="text" class="text" size="30" id="ciudad" />
</div>
<div style="clear:both; padding-left:20px; padding-right:20px">
Texto:<br />
<textarea name="message" cols="" rows="" class="textarea" id="mensaje"></textarea>

<br />
<input name="boletin" type="checkbox" id="boletin" value="1" checked="checked" />
Deseo recibir en forma gratuita el boletín mensual de noticias .<br />

<input type="submit" class="puls_form" value="Enviar" /> <input type="reset" value="Cancelar" class="puls_form" />
<br />
<br />
<strong>(*)</strong> Campos obligatorios. </div>


If boletin=1 then I would like to run the following javacode
<jos:comment>
@package Joomla!
@subpackage com_sm2emailmarketing
@copyright Copyright (C) 2006 SM2 / All Rights Reserved
@license commercial
@author SM2 <info@sm2joomla.com>
</jos:comment>


<jos:tmpl name="subscriber">
<script language="javascript" type="text/javascript">
    function submitSM2EMSubscription() {
      var coll = document.sm2EMSubscribe;
      var r = new RegExp("[^0-9A-Za-z
  • ", "i"«»);
          var errorMSG = '';
          var iserror=0;

    if (coll != null) {
    var elements = coll.elements;
    // loop through all input elements in form
    for (var i=0; i < elements.length; i++) {
    // check if element is mandatory; here mosReq=1
    if (elements.item(i).className.indexOf('required') != -1) {
    // check for empty field value
    if (elements.item(i).value == '') {
    // add up all error messages
    errorMSG += elements.item(i).getAttribute('title') + '\n';
    // notify user by changing background color, in this case to red
    elements.item(i).style.backgroundColor = "#CC0000";
    iserror=1;
    continue;
    }
    }
    }
         }
          if(iserror==1) {
    alert('{ERROR}\n'+errorMSG);
    return false;
    } else {
    return true;
          }
        }
    </script>
    <form action="<jos:«»sef>index.php?option=com_sm2emailmarketing&task=subscribe</jos:«»sef>" method="post" name="sm2EMSubscribe" id="sm2EMSubscribe" onsubmit="return submitSM2EMSubscription()">
    <jos:tmpl type="simplecondition" requiredvars="display_details" varscope="subscriber">
    <br /><br />
       <label>
    <span>{NAME}: </span><br />
    <input type="text" name="name" class="inputbox required" title="{ERRNAME}" size="17"/><br />
    </label>
    <label>
    <span>{EMAIL}: </span><br />
    <input type="text" name="email" class="inputbox required" title="{ERREMAIL}" size="17"/><br />
    </label>
    </jos:tmpl>
    <!-- Enter the 1 for HTML or 0 for text t o enable the auto setting
    of HTML or TEXT subscriptions.
    -->
    <input type="hidden" name="html" value="1" />
    <!-- -->
    <label>
    <span>{ACTION}: </span><br />
    <select name="status">
            <option value="1">{SUBSCRIBE}</option>
            <option value="0">{UNSUBSCRIBE}</option>
    </select>
    </label>
    <jos:tmpl type="simplecondition" requiredvars="display_lists" varscope="subscriber">
    <!-- Enter the ID of the list to be auto subscribed in the value field below.
    If you wish to be auto subscribed to multiple lists then copy the following
    hidden field for each list.
    -->
    <input type="hidden" name="lists
  • " value="1" />
    </jos:tmpl>
          <br />
    <input type="submit" value="{SUBMIT}" class="button" />
    </form>
    </jos:tmpl>


    I believe I would have to remove the form stuff and only leave the javascript to be executed, but not sure how to go around it. Unfortunately I do not know any javascript if I have to make changes in the code. Any help appreciated.
    admin 28
    September 14 2007, 05:30 #2222
    Hi,

    I don't have an idea about SM2 marketing But, I think you should run some piece of PHP code in the onsubmit after email box in chronoforms to check if the user has the checkbox checked, and if so it will add him to the newsletter database, how do you achieve this with javascript ?I see you have some HTML code in the javascript but not sure how do you expect this to run, do you have more info/specs ?

    Max
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    J
    jitteryjack 6
    September 14 2007, 11:08 #2228
    Well, the html code from the js would have to go, this is from the SM2 module template. What I would like is to include this Javascript or equivalent php to accomplish what this template is doing onsubmit. I think it would work if I use the same input names in my Chronoform as the jscript, but like I said, my programming abilities are ... nonexistent.
    admin 28
    September 14 2007, 18:38 #2231
    Hi jitteryjack,

    I think the best way is to concatenate the SM2 code to the main form HTML code, then once form is submitted you check with PHP if that checkbox is checked and if so use PHP to insert this user details as a subscriber, regarding the code itself this should not be hard if you can search in the SM2 code but I have no idea about that and so cant help with the code itself, sorry!!

    Good luck!!

    Max
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    Z
    zentering 8
    October 29 2007, 00:10 #3138
    Love this !! Did you resolve it, its a verry good idea.

    Would love to do the same.


    Best wishes / Z
    admin 28
    October 29 2007, 03:12 #3148
    Hi Zentring,

    Iam not sure if this code is really adding a user to the newsletter, I guess it just shows a subscription form, you can have the code shows in another page then make a redirect after form submit OR you can run PHP code to insert a subscriber!

    Cheers

    Max
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    J
    jitteryjack 6
    October 30 2007, 11:29 #3202
    Hi,
    Actually I was trying to use the code from the newsletter form to be run by chronoforms. I think its not difficult to do, but my javascript skills are at a copy paste level, so I didn't venture into trying to modify the code.

    I am sure a more experienced user could make it easily work.
    admin 28
    October 30 2007, 19:21 #3209
    Hi jitteryjack,

    Iam really not aware about the subscription process but what I understand is that we need more than JS to add some user to the newsletter database!! or at least some other form must be completed ?

    Sincerely,

    Max
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    R
    rajnath_fr 1
    November 02 2007, 20:02 #3329
    Can plz tell me the sample example how to use Chrono forms used in joomla.

    plz it was very important to me , can u plz send it to me
    raj...