Taking data from an external action form with POST

Asked

Viewed 81 times

1

Hello.

I’m having a problem trying to recover data from a form where its action is an external url.

 <form accept-charset="UTF-8" method="post" name="formIntegration" id="formIntegration" onsubmit="return DinamizeValidateForm(this)" action="https://receiver.emkt.dinamize.com/in/315723/1/1d9b" > 
<input type="hidden" name="update_mode" value="AS"><input type="hidden" name="form-code" value="7" /><input type="hidden" id="isMsg" name="isMsg" value="false" /><input type="hidden" name="redirect-url" value="http://localhost/dinamize/recebe_formulario.php"><input type="hidden" name="cmp4" value="Formul&aacute;rio de Teste"><input type="hidden" name="text-error" value=""><input type="hidden" name="double-optin" value="on"><input type="hidden" name="double-optin-text" value="T2JyaWdhZG8gcG9yIGNvbmZpcm1hciBzZXUgY2FkYXN0cm8u"><input type="hidden" name="repost-data" value="on"><input type="hidden" name="repost-data" value="http://localhost/dinamize/recebe_formulario.php"><table border="0">
                    <tr><td><label for="cmp1">E-mail</label></td></tr>
                    <tr><td class="tdValue"><input id="cmp1" name="cmp1" class="type_EMAIL field-required" type="text" value="" maxlength="80" /></td></tr>
                    <tr><td><label for="cmp2">Nome</label></td></tr>
                    <tr><td class="tdValue"><input id="cmp2" name="cmp2" class="type_VC field-required" type="text" value="" maxlength="80" /></td></tr>            <tr><td><input type="submit" id="submit" value="Cadastre-se" /></td></tr>
    </table>
</form>

<script>

    function DinamizeValidateForm(form){

        DinamizeLimpaAvisos();
        var enviar = true;
        var elem = form.elements;
        var dateElements = new Array();
        var floatElements = new Array();

        for(var i = 0; i < elem.length; i++){
            if( elem[i].type != "hidden" ){

                var classList = elem[i].className.split(" ");
                removeClass("field-error", elem[i]);
                elem[i].value = elem[i].value.trim();
                if(classList.indexOf("type_EMAIL") != -1){
                    if(!validateEmail(elem[i].value) ){
                        addClass("field-error", elem[i]);
                        enviar = false;
                    }
                }
                               if( classList.indexOf("field-required") != -1 ){
                    if(classList.indexOf("type_LVM") != -1){
                        var nameChks = elem[i].getAttribute("id");
                        var ok = false;
                        var checkboxes = document.getElementsByClassName("chk_"+nameChks);

                        removeClass("field-error", document.getElementById("containerMultiple_"+nameChks) );
                        if (checkboxes.length != 0){
                            for(var j=0; j < checkboxes.length; j++){
                                if(checkboxes[j].checked == true){
                                    ok = true;
                                    break;
                                }
                            }
                        }
                        if(!ok){
                            addClass("field-error", document.getElementById("containerMultiple_"+nameChks) );
                            enviar = false;
                        }
                    }else{
                        if( elem[i].value.trim() == "" ){
                            addClass("field-error", elem[i]);
                            enviar = false;
                        }
                    }
                }
            }
        }

            if(!enviar){
            alert("Por favor preencha o campo");
        }
    
        var isMsg = document.getElementById("isMsg").value;
        if(enviar && isMsg == "true"){
            DinamizeLoadingForm(form);
            enviar = false;
        }

        return enviar;
    }

    function DinamizeLoadingForm(form) {
        var ifrm = document.createElement("iframe");
        ifrm.setAttribute("id", "iframeFormIntegration");
        ifrm.setAttribute("name", "iframeFormIntegration");
        ifrm.style.display = "none";
        document.body.appendChild(ifrm);

        var imgReq = document.createElement("img");
        imgReq.setAttribute("id", "DinamizeImgResponse");

        imgReq.src = "https://receiver.emkt.dinamize.com/in/315723/1/1d9b/?" + serialize(form) + "&a=" + Math.floor((Math.random()*99999)+1);
        
        imgReq.style.display = "none";
        
        document.body.appendChild(imgReq);

        imgReq.onload = function () {
            DinamizePostSuccess()
        }

        imgReq.onerror = function () {
            document.getElementById("DinamizeDivMessageError").style.display = "block";
        }
    }

    function DinamizePostSuccess() {
        document.getElementById("DinamizeDivMessageAlert").style.display = "block";
        document.getElementById("formIntegration").reset();
    }

    function DinamizeLimpaAvisos() {
        var msgAlert = document.getElementById("DinamizeDivMessageAlert");
        if(msgAlert) {
            msgAlert.style.display = "none";
        }

        var msgError = document.getElementById("DinamizeDivMessageError");
        if(msgError) {
            msgError.style.display = "none";
        }

        var ifrm = document.getElementById("iframeFormIntegration");
        if(ifrm) {
            ifrm.parentNode.removeChild(ifrm);
        }

        var img = document.getElementById("DinamizeImgResponse");
        if(img) {
            img.parentNode.removeChild(img);
        }  
    }

    function validateEmail(email) {
    	var re = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        return re.test(email);
    }

    
   function addClass( classname, element ) {
        var cn = element.className;
        if( cn.indexOf( classname ) != -1 ) {
            return;
        }
        if( cn != "" ) {
            classname = " "+classname;
        }
        element.className = cn+classname;
    }

   function removeClass( classname, element ) {
       var cn = element.className;                     
	   var rxp = new RegExp( "\\s?\\b"+classname+"\\b", "g" );
       cn = cn.replace( rxp, "" );
       element.className = cn;
   }


   //função do google faz o serialize estilo JQuery
   function serialize(form){if(!form||form.nodeName!=="FORM"){return }var i,j,q=[];for(i=form.elements.length-1;i>=0;i=i-1){if(form.elements[i].name===""){continue}switch(form.elements[i].nodeName){case"INPUT":switch(form.elements[i].type){case"text":case"hidden":case"password":case"button":case"reset":case"submit":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"checkbox":case"radio":if(form.elements[i].checked){q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value))}break;case"file":break}break;case"TEXTAREA":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"SELECT":switch(form.elements[i].type){case"select-one":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"select-multiple":for(j=form.elements[i].options.length-1;j>=0;j=j-1){if(form.elements[i].options[j].selected){q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].options[j].value))}}break}break;case"BUTTON":switch(form.elements[i].type){case"reset":case"submit":case"button":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break}break}}return q.join("&")};
</script>

When I try to receive these values on the page I receive the POST from the fields, they do not return anything.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.