Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation ASAP - HELP with submitting form to Google Doc

    Hey guys, I have this site which needs to go up in a FEW HOURS and cannot figure out what I am doing wrong on this form. To be fair, I don't know much about javascript or php, so I've mainly been copying and pasting from other projects that have worked.

    Let me know if you know whats wrong! Thanks,


    HTML:
    Code:
    <div id="thanks" style="display:none; font-size:20px; color:#fff; text-align:center; margin-top:120px;"><h1 style="font-size:24px">Thank you for your support!</h1></div>
            	<form id="form" name="form" action="" method="post">
                	<h1>Get Email Updates</h1>
     				<input type="text" class="form_email" name="form_email" id="form_email" value="Email Address" onfocus="if (this.value=='Email Address') this.value='';" onblur="if (this.value=='') this.value='Email Address';"/>
           			<input type="text" class="form_zip" name="form_zip" id="form_zip" value="Zip" onfocus="if (this.value=='Zip') this.value='';" onblur="if (this.value=='') this.value='Zip';"/>
                  <div class="clearfloat" style="height:8px"></div>
                    
                  <input type="checkbox" id="c1" name="cc" class="form_check" checked="checked" /><label for="c1"><span></span>&nbsp;&nbsp;Endorse </label>
                  <div class="clearfloat" style="height:10px"></div>
                    
                  <input type="text" class="form_first" name="form_first" id="form_first" value="First Name" onfocus="if (this.value=='First Name') this.value='';" onblur="if (this.value=='') this.value='First Name';" />
                  <input type="text" class="form_last" name="form_last" id="form_last" value="Last Name" onfocus="if (this.value=='Last Name') this.value='';" onblur="if (this.value=='') this.value='Last Name';"/>
                  <input type="text" class="form_title" name="form_title" id="form_title" value="Title/Position" onfocus="if (this.value=='Title/Position') this.value='';" onblur="if (this.value=='') this.value='Title/Position';"/>
                    <br />
                    <textarea class="form_note" name="form_note" id="form_note" onfocus="if (this.value=='Please leave a note about why you support him') this.value='';" onblur="if (this.value=='') this.value='Please leave a note about why you support him';">Please leave a note about why you support him</textarea>
                    
                    
                  <div class="clearfloat" style="height:20px"></div>         
                    <div style="text-align:center"><input  type="submit" class="submit" name="form_submit" id="form_submit" value="Join the Team"/></div>
    			  <div id="form_email_error" style="margin-top: 4px; display: none; font-size:12px; text-align: center;">You must enter a valid email address</div>
                  <div id="form_error" style="margin-top: 4px; display: none; font-size:12px; text-align: center;">Please enter your zip code</div>
     			</form>

    Script.js
    Code:
    var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
    function validatesubscribe(){
    	var proceed = true; 
            if($("#form_zip").val() == "Zip"){
    		if(proceed){
    			$("#form_zip").focus();
    			$("#form_error").show();
    		}	
    		proceed = false; 
    	}
            if(proceed)
    		$("#form_email_error").hide();
    	var subscribe_emailtest = emailfilter.test($("#form_email").val());
    	if (subscribe_emailtest == false && proceed){
    		$("#form_email_error").show();
    		$("#form_email").focus();
    		proceed = false;
    	}
    	else 
    		$("#form_email_error").hide();
    	return proceed;
    	
    }

    formsubmit.js
    Code:
    $(function() {  
      $(".submit").click(function() {  
      		var proceed = validatesubscribe();
      		if(proceed){
      
      		var form_email = $("#form_email").val();
    		var form_zip = $("#form_zip").val();
    		var form_check = $("#c1").val();
    		var form_first = $("#form_first").val();
    		var form_last = $("#form_last").val();
    		var form_title = $("#form_title").val();
    		var form_note = $("#form_note").val();
    		var datastring = '&form_email=' + form_email + '&form_zip=' + form_zip + '&form_check=' + form_check + '&form_first=' + form_first + '&form_last=' + form_last + '&form_title=' + form_title + '&form_note=' + form_note;
    		$("#form").slideToggle(1000);
    		$("#thanks").slideToggle(1000);
    		$.ajax({  type: "POST",   url: "process.php", data: datastring});
      
      return false;
      }
      
      return false;
      });  
    });

    Process.php
    PHP Code:
    <?php
    //INITIALIZE GDATA LIBRARY

    $email $_POST['form_email'];
    $zip $_POST['form_zip'];
    $check $_POST['form_check'];
    $fname $_POST['form_first'];
    $lname $_POST['form_last'];
    $title $_POST['form_title'];
    $note $_POST['form_note'];
    $date date('m:d:Y H:i:s');

    require_once 
    'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata_AuthSub');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
    Zend_Loader::loadClass('Zend_Gdata_Docs');
    // Your google account username
    $username 'removed for security';
    // Your google account password
    $password 'removed for security';
    // Google Spreadsheet Key
    $key 'removed for security';
    $service Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
    $client Zend_Gdata_ClientLogin::getHttpClient($username$password$service);
    $spreadSheetService = new Zend_Gdata_Spreadsheets($client);

    //POST TO GOODLE DOC
    $rowData = array(
        
    'timestamp' => $date'firstname' => $fname'lastname' => $lname'emailaddress' => $email'zip' => $zip'position/title' => $title'endorse?' => $check'note' => $note
    );
    try {
        
    $insertedListEntry $spreadSheetService->insertRow($rowData$key);
    }
    catch(
    Zend_Gdata_App_HttpException $exception) {
        echo 
    "Error: ".$exception->getResponse()->getRawBody();
    }
    ?>
    Last edited by monkeysniffer08; 08-01-2013 at 08:57 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •