2012-11-30 2 views
0

제출 양식 단추에 여러 작업을 수행 할 수 있는지 궁금합니다. 현재 AJAX를 사용하여 Google 스프레드 시트로 전송되는 사용자 정의 양식을 사용 중입니다. 나는 또한 Blueimp Jquery File Upload 플러그인을 사용하고있다. 내가 원하는 것은 모든 관련 정보를 Google 스프레드 시트로 전송하고 업로드 한 이미지를 내 서버로 전송할 수 있다는 것입니다. Blueimp Jquery Upload를 포함하지 않고 Google 스프레드 시트를 사용하여 여러 공동 작업자의 데이터에 액세스 할 수있는 잠재적 인 솔루션을 공개합니다.양식 단추에 여러 작업을 수행 할 수 있습니까?

파일 업로드에 정통하지 않으므로 사과하지 않으시 고 궁금한 점이 있으시면 부탁드립니다. 그리고 모든 관련 정보를 제공하기 위해 최선을 다할 것입니다.

구글 스프레드 시트 코드 제출은 양식 제출 버튼 (또는 그 문제에 대한 모든 다른 입력)이있는 경우

// Handle form submission 
$('form').submit(function(e) { 
    var button = $('input[type=submit]', this), 
     data = $(this).serialize();` 

    e.preventDefault(); 
    if (validate($(this))) { 
     button.button('loading'); 
     $.ajax({ 
      type: 'POST', 
      url: formUrl, 
      data: data, 
      complete: function() { 
       button.button('reset'); 
       window.location = 'index.html#new'; 
      } 
     }); 
    } 

    function validate(form) { 
     $('.control-group').removeClass('error'); 
     $('input, textarea', form).each(function() { 
      var tag = $(this)[0].tagName.toLowerCase(), 
       type = $(this).attr('type'); 

      // Validate radio buttons 
      if (tag === 'input' && type === 'radio') { 
       var name = $(this).attr('name'); 
       if ($('[name="' + name + '"]:checked').length < 1) { 
        $(this).parent().parent().parent().addClass('error'); 
       } 
      } 

      // Validate text fields 
      if ((tag === 'input' && type === 'text') || tag === 'textarea') { 
       if ($(this).val() === '' && !$(this).parent().hasClass('radio')) { 
        $(this).parent().parent().addClass('error'); 
       } 
      } 
     }); 

     if ($('.control-group.error').length < 1) return true; 
     $('.control-group.error').length 

     $('html, body').animate({ 
      scrollTop: $('.control-group.error').offset().top - 20 
     }, 500); 

     return false; 
    } 
}); 

답변

1

가 :

<button href="#" id="formButton" type="button">Submit</button> 

자바 스크립트를 사용하여, 당신은에 클릭 이벤트를 만들 버튼을 사용하여 양식 제출 :

$('#formButton').click(submitMultipleForms()); 

그런 다음 함수에서 다음을 제출할 수 있습니다. 그는 형성한다. 각 양식에는 ID가 있어야합니다.

function submitMultipleForms() { 
     $("#form1").submit(function() { //Handler for form1 
            }); 
     $("#form2").submit(function() { //Handler for form2 
            }); 
} 
+0

감사합니다. 시도해 보겠습니다. –

관련 문제