6 Replies - 4512 Views - Last Post: 24 May 2011 - 10:22 PM

#1 infogeniuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-May 11

Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 12:29 PM

Trying to get this code to insert javascript variables into hidden fields in form using "function populateHiddenFields(f)" . Any thoughts on what I have wrong? onsubmit command? variable definitions? i cant seem to close the loop. No error, just no variables inserted.

<!DOCTYPE html> 
<html dir="ltr" lang="en-US"> 
<head> 
<meta charset="UTF-8" /> 
<title>iGz-test | iGz :: Forms</title> 
<link rel="profile" href="http://gmpg.org/xfn/11" /> 
<link rel="stylesheet" type="text/css" media="all" href="http://forms.infogeniuz.com/wp-content/themes/twentyten/style.css" /> 
<link rel="pingback" href="http://forms.infogeniuz.com/xmlrpc.php" /> 
<meta name='robots' content='noindex,nofollow' /> 
<!-- Form Script for Google Analytics Cookie -->
<script type="text/javascript"> 
   var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
   document.write("<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'>" + "</sc" + "ript>"); 
</script> 

<script type='text/javascript'>
var pageTracker = _gat._getTracker("UA-1-1");
pageTracker._trackPageview();

//
// This is a function that I "borrowed" from the urchin.js file.
// It parses a string and returns a value.  I used it to get
// data from the __utmz cookie
//
function _uGC(l,n,s) {
 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
 var i,i2,i3,c="-";
 i=l.indexOf(n);
 i3=n.indexOf("=")+1;
 if (i > -1) {
  i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
  c=l.substring((i+i3),i2);
 }
 return c;
}

// 
// Get the __utmz cookie value. This is the cookies that 
// stores all campaign information. 
// 
var z = _uGC(document.cookie, '__utmz=', ';'); 
// 
// The cookie has a number of name-value pairs. 
// Each identifies an aspect of the campaign. 
// 
// utmcsr  = campaign source 
// utmcmd  = campaign medium 
// utmctr  = campaign term (keyword) 
// utmcct  = campaign content  
// utmccn  = campaign name 
// utmgclid = unique identifier used when AdWords auto tagging is enabled 
// 
// This is very basic code. It separates the campaign-tracking cookie 
// and populates a variable with each piece of campaign info. 
// 
var source  = _uGC(z, 'utmcsr=', '|'); 
var medium  = _uGC(z, 'utmcmd=', '|'); 
var term    = _uGC(z, 'utmctr=', '|'); 
var content = _uGC(z, 'utmcct=', '|'); 
var campaign = _uGC(z, 'utmccn=', '|'); 
var gclid   = _uGC(z, 'utmgclid=', '|'); 
// 
// The gclid is ONLY present when auto tagging has been enabled. 
// All other variables, except the term variable, will be '(not set)'. 
// Because the gclid is only present for Google AdWords we can 
// populate some other variables that would normally 
// be left blank. 
// 
if (gclid !="-") { 
      source = 'google'; 
      medium = 'cpc'; 
} 
// Data from the custom segmentation cookie can also be passed 
// back to your server via a hidden form field 
var csegment = _uGC(document.cookie, '__utmv=', ';'); 
if (csegment != '-') { 
      var csegmentex = /[1-9]*?\.(.*)/;
      csegment    = csegment.match(csegmentex); 
      csegment    = csegment[1]; 
} else { 
      csegment = '(not set)'; 
} 

//
// One more bonus piece of information.  
// We're going to extract the number of visits that the visitor
// has generated.  It's also stored in a cookie, the __utma cookis
// 
var a = _uGC(document.cookie, '__utma=', ';');
var aParts = a.split(".");
var nVisits = aParts[5];

function populateHiddenFields(f) { 
      f.source.value  = input_10; 
      f.medium.value  = input_11; 
      f.term.value    = input_12; 
      f.content.value = input_13; 
      f.campaign.value = input_14; 
      f.segment.value = input_15; 
      f.numVisits.value = input_16;

//     alert('source='+f.source.value); 
//     alert('medium='+f.medium.value); 
//     alert('term='+f.term.value); 
//     alert('content='+f.content.value); 
//     alert('campaign='+f.campaign.value); 
//     alert('custom segment='+f.segment.value); 
//     alert('number of visits='+f.numVisits.value);

//      return false; 
} 
</script> 
<!-- END Form Script for Google Analytics Cookie --><link rel="alternate" type="application/rss+xml" title="iGz :: Forms &raquo; Feed" href="http://forms.infogeniuz.com/feed/" /> 
<link rel="alternate" type="application/rss+xml" title="iGz :: Forms &raquo; Comments Feed" href="http://forms.infogeniuz.com/comments/feed/" /> 
<link rel='stylesheet' id='gforms_css-css'  href='http://forms.infogeniuz.com/wp-content/plugins/gravityforms/css/forms.css?ver=1.5.2.1' type='text/css' media='all' /> 
<script type='text/javascript' src='http://forms.infogeniuz.com/wp-includes/js/l10n.js?ver=20101110'></script> 
<script type='text/javascript' src='http://forms.infogeniuz.com/wp-includes/js/jquery/jquery.js?ver=1.4.4'></script> 
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://forms.infogeniuz.com/xmlrpc.php?rsd" /> 
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://forms.infogeniuz.com/wp-includes/wlwmanifest.xml" /> 
<link rel='index' title='iGz :: Forms' href='http://forms.infogeniuz.com/' /> 
<link rel='prev' title='infogeniuz' href='http://forms.infogeniuz.com/infogeniuz/' /> 
<meta name="generator" content="WordPress 3.1.2" /> 
<link rel='canonical' href='http://forms.infogeniuz.com/igz-test/' /> 
</head> 
 
<body class="page page-id-42 page-template page-template-default logged-in"> 
<div id="wrapper" class="hfeed"> 
	<div id="header"> 
		<div id="masthead"> 
			<div id="branding" role="banner"> 
								<div id="site-title"> 
					<span> 
						<a href="http://forms.infogeniuz.com/" title="iGz :: Forms" rel="home">iGz :: Forms</a> 
					</span> 
				</div> 
				<div id="site-description">Just another WordPress site</div> 
 
										<img src="http://forms.infogeniuz.com/wp-content/themes/twentyten/images/headers/inkwell.jpg" width="940" height="198" alt="" /> 
								</div><!-- #branding --> 
 
			<div id="access" role="navigation"> 
			  				<div class="skip-link screen-reader-text"><a href="#content" title="Skip to content">Skip to content</a></div> 
								<div class="menu"><ul><li ><a href="http://forms.infogeniuz.com/" title="Home">Home</a></li><li class="page_item page-item-42 current_page_item"><a href="http://forms.infogeniuz.com/igz-test/" title="iGz-test">iGz-test</a></li><li class="page_item page-item-5"><a href="http://forms.infogeniuz.com/infogeniuz/" title="infogeniuz">infogeniuz</a></li></ul></div> 
			</div><!-- #access --> 
		</div><!-- #masthead --> 
	</div><!-- #header --> 
 
	<div id="main"> 
 
		<div id="container"> 
			<div id="content" role="main"> 
 
			
 
				<div id="post-42" class="post-42 page type-page status-publish hentry"> 
											<h1 class="entry-title">iGz-test</h1> 
					
					<div class="entry-content"> 
						
                <div class='gform_wrapper' id='gform_wrapper_1' ><form method='post' enctype='multipart/form-data'  id='gform_1'  action='http://forms.infogeniuz.com/igz-test/' onsubmit='populateHiddenFields(this);'> 
                        <div class='gform_body'> 
                            <ul id='gform_fields_1' class='gform_fields right_label'><li id='field_1_3' class='gfield' ><label class='gfield_label' for='input_1_3.3'>Name<span class='gfield_required'>*</span></label><div class='ginput_complex ginput_container' id='input_1_3'><span id='input_1_3_3_container' class='ginput_left'><input type='text' name='input_3.3' id='input_1_3.3' value='' tabindex='1' /><label for='input_1_3.3'>First</label></span><span id='input_1_3_6_container' class='ginput_right'><input type='text' name='input_3.6' id='input_1_3.6' value='' tabindex='2' /><label for='input_1_3.6'>Last</label></span></div></li><li id='field_1_2' class='gfield' ><label class='gfield_label' for='input_1_2'>Email<span class='gfield_required'>*</span></label><div class='ginput_complex ginput_container' id='input_1_2_container'><span id='input_1_2_1_container' class='ginput_left'><input type='text' name='input_2' id='input_1_2' value='' tabindex='3' /><label for='input_1_2'>Enter Email</label></span><span id='input_1_2_2_container' class='ginput_right'><input type='text' name='input_2_2' id='input_1_2_2' value='' tabindex='4' /><label for='input_1_2_2'>Confirm Email</label></span></div></li><li id='field_1_4' class='gfield' ><label class='gfield_label' for='input_1_4'>Subject<span class='gfield_required'>*</span></label><div class='ginput_container'><input name='input_4' id='input_1_4' type='text' value='' class='medium'  tabindex='5'  /></div></li>

<li id='field_1_5' class='gfield' ><label class='gfield_label' for='input_1_5'>Message<span class='gfield_required'>*</span></label><div class='ginput_container'><textarea name='input_5' id='input_1_5' class='textarea medium' tabindex='6'  rows='10' cols='50'></textarea></div></li>

<li id='field_1_7' class='gfield     gform_hidden' ><input name='input_7' id='input_1_7' type='hidden' class='gform_hidden' value='99.117.218.223' /></li><li id='field_1_8' class='gfield     gform_hidden' ><input name='input_8' id='input_1_8' type='hidden' class='gform_hidden' value='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24' /></li>

<li id='field_1_9' class='gfield     gform_hidden' ><input name='input_9' id='input_1_9' type='hidden' class='gform_hidden' value='http://forms.infogeniuz.com/' /></li>

<li id='field_1_10' class='gfield     gform_hidden' ><input name='input_10' id='input_1_10' type='hidden' class='gform_hidden' value='' /></li><li id='field_1_11' class='gfield     gform_hidden' ><input name='input_11' id='input_1_11' type='hidden' class='gform_hidden' value='' /></li>

<li id='field_1_12' class='gfield     gform_hidden' ><input name='input_12' id='input_1_12' type='hidden' class='gform_hidden' value='' /></li>

<li id='field_1_13' class='gfield     gform_hidden' ><input name='input_13' id='input_1_13' type='hidden' class='gform_hidden' value='' /></li>

<li id='field_1_14' class='gfield     gform_hidden' ><input name='input_14' id='input_1_14' type='hidden' class='gform_hidden' value='' />

</li><li id='field_1_15' class='gfield     gform_hidden' ><input name='input_15' id='input_1_15' type='hidden' class='gform_hidden' value='' /></li>

<li id='field_1_16' class='gfield     gform_hidden' ><input name='input_16' id='input_1_16' type='hidden' class='gform_hidden' value='' /></li> 
                            </ul></div> 
        <div class='gform_footer right_label'> <input type='submit' id='gform_submit_button_1' class='button gform_button' value='Submit' tabindex='7' /><div class='gform_edit_link'><a href='http://forms.infogeniuz.com/wp-admin/admin.php?page=gf_edit_forms&amp;id=1'>Edit this form</a></div> 
            <input type='hidden' class='gform_hidden' name='is_submit_1' value='1' /> 
            <input type='hidden' class='gform_hidden' name='gform_submit' value='1' /> 
            <input type='hidden' class='gform_hidden' name='gform_unique_id' value='4ddc0617d712c' /> 
            <input type='hidden' class='gform_hidden' name='state_1' value='YToyOntpOjA7czo2OiJhOjA6e30iO2k6MTtzOjMyOiIyYWFmYzdkODRkNWYwMTc2YWVjNGJmNTg2NTE4YTU3OSI7fQ==' /> 
            <input type='hidden' class='gform_hidden' name='gform_target_page_number_1' id='gform_target_page_number_1' value='0' /> 
            <input type='hidden' class='gform_hidden' name='gform_source_page_number_1' id='gform_source_page_number_1' value='1' /> 
            <input type='hidden' name='gform_field_values' value='' /> 
            
        </div> 
                </form> 
                </div> 
												<span class="edit-link"><a class="post-edit-link" href="http://forms.infogeniuz.com/wp-admin/post.php?post=42&amp;action=edit" title="Edit Page">Edit</a></span>					</div><!-- .entry-content --> 
				</div><!-- #post-## --> 
 
				
			<div id="comments"> 
 
 
	<p class="nocomments">Comments are closed.</p> 
 
 
								
</div><!-- #comments --> 
 
 
			</div><!-- #content --> 
		</div><!-- #container --> 
 
 
		<div id="primary" class="widget-area" role="complementary"> 
			<ul class="xoxo"> 
 
<li id="search-2" class="widget-container widget_search"><form role="search" method="get" id="searchform" action="http://forms.infogeniuz.com/" > 
	<div><label class="screen-reader-text" for="s">Search for:</label> 
	<input type="text" value="" name="s" id="s" /> 
	<input type="submit" id="searchsubmit" value="Search" /> 
	</div> 
	</form></li><li id="recent-comments-2" class="widget-container widget_recent_comments"><h3 class="widget-title">Recent Comments</h3><ul id="recentcomments"></ul></li><li id="archives-2" class="widget-container widget_archive"><h3 class="widget-title">Archives</h3>		<ul> 
				</ul> 
</li><li id="categories-2" class="widget-container widget_categories"><h3 class="widget-title">Categories</h3>		<ul> 
<li>No categories</li>		</ul> 
</li><li id="meta-2" class="widget-container widget_meta"><h3 class="widget-title">Meta</h3>			<ul> 
			<li><a href="http://forms.infogeniuz.com/wp-admin/">Site Admin</a></li>			<li><a href="http://forms.infogeniuz.com/wp-login.php?action=logout&_wpnonce=77e10f5046">Log out</a></li> 
			<li><a href="http://forms.infogeniuz.com/feed/" title="Syndicate this site using RSS 2.0">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li> 
			<li><a href="http://forms.infogeniuz.com/comments/feed/" title="The latest comments to all posts in RSS">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li> 
			<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress.org</a></li> 
						</ul> 
</li>			</ul> 
		</div><!-- #primary .widget-area --> 
 
	</div><!-- #main --> 
 
	<div id="footer" role="contentinfo"> 
		<div id="colophon"> 
 
 
 
			<div id="site-info"> 
				<a href="http://forms.infogeniuz.com/" title="iGz :: Forms" rel="home"> 
					iGz :: Forms				</a> 
			</div><!-- #site-info --> 
 
			<div id="site-generator"> 
								<a href="http://wordpress.org/" title="Semantic Personal Publishing Platform" rel="generator">Proudly powered by WordPress.</a> 
			</div><!-- #site-generator --> 
 
		</div><!-- #colophon --> 
	</div><!-- #footer --> 
 
</div><!-- #wrapper --> 
 
</body> 
</html> 



Is This A Good Question/Topic? 0
  • +

Replies To: Problem w/ onsubmit and hidden variables

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10821
  • View blog
  • Posts: 40,346
  • Joined: 27-December 08

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 12:31 PM

Moved to Javascript. Please note that Java != Javascript.
Was This Post Helpful? 0
  • +
  • -

#3 infogeniuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-May 11

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 12:34 PM

View Postmacosxnerd101, on 24 May 2011 - 12:31 PM, said:

Moved to Javascript. Please note that Java != Javascript.


sorry. :(
Was This Post Helpful? 0
  • +
  • -

#4 infogeniuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-May 11

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 12:45 PM

ie: the javascript works with a simple hidden form and alerts... see here.
http://infogeniuz.com/test-ga.html

something just isnt right with adding variables to the new hidden fields.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,444
  • Joined: 08-June 10

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 02:12 PM

I donít see input_10 to input_16 defined anywhere.
Was This Post Helpful? 0
  • +
  • -

#6 infogeniuz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-May 11

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 02:20 PM

View PostDormilich, on 24 May 2011 - 02:12 PM, said:

I donít see input_10 to input_16 defined anywhere.


do you mean in lines 93-100 or 170-180...?

should it be...

function populateHiddenFields(f) { 
      f.source.value  = input_1_10; 
      f.medium.value  = input_1_11; 
      f.term.value    = input_1_12; 
      f.content.value = input_1_13; 
      f.campaign.value = input_1_14; 
      f.segment.value = input_1_15; 
      f.numVisits.value = input_1_16;


Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,444
  • Joined: 08-June 10

Re: Problem w/ onsubmit and hidden variables

Posted 24 May 2011 - 10:22 PM

input_1_10 will still be undefined as it is a mere global variable. you would probably need something like f.source.value = document.forms[0].input_1_10.value; when you want to read form fields.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1