Support » Plugin: cformsII » Add js event on success

  • ResolvedPlugin Contributor Németh Balázs


    It would be really useful to have a javascript event on successful form sends.
    You could extend the cforms_setsuccessmessage function with the code below.

    	var event; // The custom event that will be created
    	if (document.createEvent) {
    		event = document.createEvent("HTMLEvents");
    		event.initEvent("formsent", true, true); // name, bubbling, cancelable
    	} else { // IE
    		event = document.createEventObject();
    		event.eventType = "formsent";
    	event.eventName = "formsent";
    	event.formNumber = no;
    	if (document.createEvent) {
    	} else { // IE
    		document.body.fireEvent("on" + event.eventType, event);

    Then anyone could access the event with the code below:

    document.body.addEventListener('formsent', function (e) {
    	console.log('form #' + e.formNumber + ' sent');
    }, true);

    This could be used for example to fire a Google Analytics event.

Viewing 1 replies (of 1 total)
  • Plugin Author bgermann


    Okay, I will probably include event generation in one of the next versions. Thank you for the suggestion.

Viewing 1 replies (of 1 total)
  • The topic ‘Add js event on success’ is closed to new replies.