2013-06-10 8 views
0

데이터를 Sugar CRM에 게시하는 양식이 있습니다. 데이터가 Firefox에 성공적으로 제출되었지만 올바르게 리디렉션되지 않습니다. Chrome에서 데이터가 전송되지 않고 올바르게 리디렉션됩니다.자바 스크립트 양식 제출

<form method="POST" class="brochurelead webtoleadform" name="WebToLeadForm" id="WebToLeadForm">  
    <fieldset> 
    <label for="firstname">First name*:</label> 
    <input type="text" name="first_name" id="first_name" /> 
    <br /> 
    <label for="lastname">Last name*:</label> 
    <input type="text" name="last_name" id="last_name" /> 
    <br /> 
    <label for="phone_work">Primary phone*:</label> 
    <input type="text" name="phone_work" id="phone_work" onchange="validateHuman();"/> 
    <br /> 
    <label for="email">Email*:</label> 
    <input type="text" name="email1" id="email1" onchange="validateEmailAdd();" /> 
    <span style="padding-left:268px"><input type="submit" value="Download" name="Submit" class="button" onclick="submit_form();" /> 
</fieldset1> 

    <input type="hidden" name="lead_source" id="lead_source" value="Brochure Download" /> 
    <input type="hidden" name="user" id="user" value="lead_capture_form" /> 
    <input type="hidden" value="dbce057c" name="campaign_id" id="campaign_id" /> 
    <input type="hidden" value="http://www.somewebsite.com/somearticle" name="redirect" id="redirect" /> 
    <input type="hidden" value="blahblah" name="assigned_user_id" id="assigned_user_id" /> 
    <input type="hidden" value="first_name;last_name;phone_work;email1;" name="req_id" id="req_id" /> 
    <input type="hidden" value="<?php echo $article->category; ?>" name="area_of_interest_c" id="area_of_interest_c"> 
    <input type="hidden" name="probability_c" id="probability_c" value="1" /> 
    <input type="hidden" id="human" name="human" value="0"> 
</form> 

이 양식을 처리하기위한 내 자바 스크립트입니다 :

function submit_form(){ 
    if(typeof(validateCaptchaAndSubmit)!='undefined'){ 
     validateCaptchaAndSubmit(); 
    }else{ 
     check_webtolead_fields(); 
    } 
} 

function check_webtolead_fields(){ 
    if(document.getElementById('req_id') != null){ 
     var reqs=document.getElementById('req_id').value; 
     reqs = reqs.substring(0,reqs.lastIndexOf(';')); 
     var req_fields = new Array(); 
     var req_fields = reqs.split(';'); 
     nbr_fields = req_fields.length; 
     var req = true; 
     for(var i=0;i<nbr_fields;i++){ 
      if(document.getElementById(req_fields[i]).value.length <=0 || document.getElementById(req_fields[i]).value==0){ 
       req = false; 
       break; 
      } 
     } 
     if(req && document.getElementById('human').value == '50'){ 
      document.WebToLeadForm.action = "http://crm.somewebsite.com/index.php?entryPoint=WebToLeadCapture"; 
      document.WebToLeadForm.submit(); 
      window.location = document.getElementById('redirect').value; 
      return true; 
     } 
     else{ 
      alert('Please provide all the required fields'); 
      return false; 
     } 
     return false 
    } 
    else{ 
     document.WebToLeadForm.action = "http://crm.somewebsite.com/index.php?entryPoint=WebToLeadCapture"; 
     document.WebToLeadForm.submit(); 
     window.location = document.getElementById('redirect').value; 
    } 
} 

function validateEmailAdd(){ 
    if(document.getElementById('email1').value.length >0) { 
     if(document.getElementById('email1').value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == null){ 
      alert('Not a valid email address'); 
     } 
    } 
} 

function validateHuman(){ 
    document.getElementById('human').value = "50"; 
} 
+0

'싫증나 지 않습니다.': 오류가 있습니까? –

+0

오류가 없습니다. 양식은 파이어 폭스에서 데이터를 올바르게 제출하지만 리다이렉트하지는 않습니다. 대신 Chrome의 'index.php? entryPoint = WebToLeadCapture' URL에 붙여 넣어 올바른 URL로 리디렉션하지만 데이터를 제출하지 마십시오 – showFocus

답변

2

당신이 양식을 제출하고 동시에 페이지의 위치를 ​​설정하려고 때문입니다. 그것은 일어나지 않을 것입니다. 그것은 경쟁 조건입니다!

리디렉션 할 때 Ajax 깡통을 사용하여 양식을 제출해야하거나 서버 방향이 실제로 리디렉션을 수행해야합니다.

+0

맞습니다! 이 줄'window.location = document.getElementById ('redirect'). value;'는이 줄을 필요로하지 않습니다''가 전달되어 서버 측에서 처리됩니다. 감사! – showFocus

관련 문제