heyfletch
4/17/2012 - 7:05 PM

MageMonkeySubscribe.phtml with some fixes to prevent javascript errors, but does not actually subscribe customer

MageMonkeySubscribe.phtml with some fixes to prevent javascript errors, but does not actually subscribe customer

<?php
	$check = $this->checkStatus();
	$auto  = (($check === 1) OR ($check === 3));
?>
<script type="text/javascript">
addSubscribeToPost = function (element)
{
	if($('magemonkey-subscribe'))
	{
		$('magemonkey-subscribe').remove();
	}

/* Attempt to fix IE errors */
	if(element.checked)
	{		
		//Element.insert(Form.findFirstElement(payment.form),
			//new Element('input', { name: "magemonkey_subscribe", id: "magemonkey-subscribe", value: "1", type: "hidden" }) );
		Element.insert($('subscribe_button'),new Element('input', { name: "magemonkey_subscribe", id: "magemonkey-subscribe", value: "1", type: "hidden" }));
	}

}
/* End attempt to fix IE errors */

addElementToPost = function (element){
	var formInputId = element.readAttribute('id') + '-serialize';
	if($(formInputId)){
	 $(formInputId).remove();
	}
	var inp = new Element('input', { name: element.readAttribute('name'), id: formInputId, value: element.getValue(), type: "hidden" });

	Element.insert( Form.findFirstElement(payment.form), inp);
}
</script>
<?php /* Attempt to fix IE errors */ ?>
<div class="buttons-set a-left"<?php if($check === 3): ?> style="display:none;"<?php endif;?>>
	<div id="subscribe_button"></div>
	<input<?php if($auto): ?> checked="checked"<?php endif;?> type="checkbox" onchange="addSubscribeToPost(this);" name="magemonkey_trigger" id="magemonkey-trigger" value="1" title="<?php echo $this->htmlEscape($this->__('Sign Up for Newsletter')) ?>" class="checkbox" />
	<label for="magemonkey-trigger"><?php echo $this->htmlEscape($this->__('Sign Up for Newsletter')) ?></label>
</div>
<?php /* End attempt to fix IE errors */ ?>

<?php echo $this->getChildHtml('left.monkeysignup'); ?>

<script type="text/javascript">
	addSubscribeToPost($('magemonkey-trigger'));

	if( $$('div#checkout-step-review div.monkey-multisubscribe').length ){

	  var event = 'change';

	  //Radio||Checkbox
	  $$('div#checkout-step-review div.monkey-multisubscribe input').each(function(input){

		  if(input.readAttribute('type') == 'radio'){
			  event = 'click';
		  }

		  input.observe(event, function(){
			  addElementToPost(this);
		  });
	  });

	  $$('div#checkout-step-review div.monkey-multisubscribe select').each(function(ddl){
		  ddl.observe(event, function(){
			  addElementToPost(this);
		  });
	  });

	}
</script>