insert into #__sfg_forms set `status`='1',`name`='Registration_custom',`description`='',`form`='\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n /*******************************************************************/\n/* SmartFormer Gold © Form PHP controller */\n/* */\n/* Product of IToris © 2009 http://www.itoris.com */\n/* */\n/*******************************************************************/\n\n$session = Mage::getSingleton(\'customer/session\');\nif ($session->isLoggedIn()) {\n Mage::app()->getResponse()->setRedirect(Mage::getUrl(\'customer/account\'));\n return;\n}\n\n$form->getPostedValues();\n\n$form->doAfterSubmitAction();\n\nif($form->page == 2){\n register($form);\n}\n\n\n\n$form->renderForm();\n\nMage::app()->getLayout()->getBlock(\'root\')->setTemplate(\'page/1column.phtml\');\nMage::app()->getLayout()->getMessagesBlock()->setMessages($session->getMessages(true));\necho Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml().$form->page_html;\n\nfunction register($form){\n\n $session = Mage::getSingleton(\'customer/session\');\n if ($session->isLoggedIn()) {\n\n $form->page = 3;\n return;\n }\n $session->setEscapeMessages(true); // prevent XSS injection in user input\n if (true) {\n $errors = array();\n\n if (!$customer = Mage::registry(\'current_customer\')) {\n $customer = Mage::getModel(\'customer/customer\')->setId(null);\n }\n\n $data = $form->data;\n \n $data[\'street\'] = array($data[\'street\']);\n\n foreach (Mage::getConfig()->getFieldset(\'customer_account\') as $code=>$node) {\n if ($node->is(\'create\') && isset($data[$code])) {\n if ($code == \'email\') {\n $data[$code] = trim($data[$code]);\n }\n $customer->setData($code, $data[$code]);\n }\n }\n\n if(isset($data[\'is_subscribed\']) && $data[\'is_subscribed\'] == 1){\n $customer->setIsSubscribed(1);\n }\n\n /**\n * Initialize customer group id\n */\n $customer->getGroupId();\n\n if (isset($data[\'create_address\'])) {\n $address = Mage::getModel(\'customer/address\')\n ->setData($data)\n ->setIsDefaultBilling(isset($data[\'billing_default\']))\n ->setIsDefaultShipping(isset($data[\'shipping_default\']))\n ->setId(null);\n $customer->addAddress($address);\n\n $errors = $address->validate();\n if (!is_array($errors)) {\n $errors = array();\n }\n }\n\n try {\n $validationCustomer = $customer->validate();\n if (is_array($validationCustomer)) {\n $errors = array_merge($validationCustomer, $errors);\n }\n $validationResult = count($errors) == 0;\n\n if (true === $validationResult) {\n $customer->save();\n\n if ($customer->isConfirmationRequired()) {\n $customer->sendNewAccountEmail(\'confirmation\', $session->getBeforeAuthUrl());\n $session->addSuccess(\'Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href=\"\'.Mage::helper(\'customer\')->getEmailConfirmationUrl($customer->getEmail()).\'\">click here</a>.\' );\n //$this->_redirectSuccess(Mage::getUrl(\'*/*/index\', array(\'_secure\'=>true)));\n return;\n }\n else {\n $session->setCustomerAsLoggedIn($customer);\n $url = _welcomeCustomer($customer);\n Mage::app()->getResponse()->setRedirect($url);\n // $this->_redirectSuccess($url);\n return;\n }\n } else {\n $session->setCustomerFormData($data);\n if (is_array($errors)) {\n foreach ($errors as $errorMessage) {\n $session->addError($errorMessage);\n }\n }\n else {\n $session->addError(\'Invalid customer data\');\n }\n }\n }\n catch (Mage_Core_Exception $e) {\n $session->setCustomerFormData($data);\n if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {\n $url = Mage::getUrl(\'customer/account/forgotpassword\');\n $message = \'There is already an account with this emails address. If you are sure that it is your email address, <a href=\"\'.$url.\'\">click here</a> to get your password and access your account.\';\n $session->setEscapeMessages(false);\n }\n else {\n $message = $e->getMessage();\n }\n $session->addError($message);\n }\n catch (Exception $e) {\n $session->setCustomerFormData($data)\n ->addException($e, \'Can\\\'t save customer\');\n }\n }\n $form->page--;\n\n}\n\n function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)\n {\n Mage::getSingleton(\'customer/session\')->addSuccess(\'Thank you for registering with \'.Mage::app()->getStore()->getFrontendName());\n\n $customer->sendNewAccountEmail($isJustConfirmed ? \'confirmed\' : \'registered\');\n\n $successUrl = Mage::getUrl(\'customer/account/index\', array(\'_secure\'=>true));\n if (Mage::getSingleton(\'customer/session\')->getBeforeAuthUrl()) {\n $successUrl = Mage::getSingleton(\'customer/session\')->getBeforeAuthUrl(true);\n }\n return $successUrl;\n }\n \n \n /*******************************************************************/\n// SmartFormer Gold © Form JS controller\n//\n// Product of IToris © 2009 http://www.itoris.com\n//\n/*******************************************************************/\n\nfunction formSubmit(submitter) {\n //getting list of elements\n var nodes = document.getElementById(\'sfg_fieldset\').childNodes;\n var objects = Array();\n for (var i=0; i<nodes.length; i++) if (nodes[i].tagName) objects[objects.length] = nodes[i];\n // perform validation\n var isFormValid = true;\n for (var vl=0; vl<sfg_validation.length; vl++) if (window[\'validator\'+sfg_validation[vl][1]] && objects[sfg_validation[vl][0]]) {\n var msg = window[\'validator\'+sfg_validation[vl][1]](objects[sfg_validation[vl][0]], sfg_validation[vl][2], sfg_validation[vl][3] ? sfg_validation[vl][3] : \'\');\n if (msg) {\n isFormValid = false;\n alert(msg);\n objects[sfg_validation[vl][0]].focus();\n return;\n }\n }\n \n var countryId = document.getElementsByName(\'country_id\')[0];\n if(countryId){\n if(countryId.value == \'US\'){\n if(getByName(\'region_id\').value == \'\'){\n alert(\'Field: State/Region. Field is required\');\n return;\n }\n }else{\n if(getByName(\'region\').value == \'\'){\n alert(\'Field: State/Region. Field is required\');\n return;\n }\n }\n }\n \n document.getElementById(\'sfg_submitter\').value = submitter;\n document.sfgForm.submit();\n}\n\n\nfunction getByName(name){\n return document.getElementsByName(name)[0];\n}\n\nfunction dobChanged(){\n var data = new Array();\n data[1] = getByName(\'dob_day\').value;\n data[0] = getByName(\'dob_month\').value;\n data[2] = getByName(\'dob_year\').value;\n \n var value = data.join(\'/\');\n getByName(\'dob\').value = value;\n \n}\n\nfunction changeRegionInput(){\n var contry = getByName(\'country_id\').value;\n\n if(contry == \'US\'){\n getByName(\'region\').style.display = \'none\';\n getByName(\'region_id\').style.display = \'block\';\n \n }else{\n getByName(\'region_id\').style.display = \'none\';\n getByName(\'region\').style.display = \'block\';\n }\n}\n\n Event.observe(window, \'load\', function() {\n changeRegionInput();\n });\n \n \n <!-- SmartFormer Gold code part -->\n\n<form action=\"\" method=\"post\" name=\"sfgForm\" enctype=\"multipart/form-data\">\n<%form_html%>\n</form>\n\n<!-- End of SmartFormer Gold code part -->\n \n \n #sfg_err_message {\n font-family: Arial;\n font-size: 12px;\n font-weight: bold;\n color: #ff0000;\n}\n \n \n \n \n \n \n \n \n \n \n \n \n