how to add new fieds and use existing address fields in magento custom regstration form - magento

hi i am new to magento.. i need some help..
i am able to add address fields in form in my view(phtml file) but that fields data is not being
saved . how could i be able to save those fields?
code for address field in phtml file
<div class="form-group margin_top">
<label for="street_1" class="required col-md-4 control-label"><?php echo $this->__('Adresse') ?><em>* :</em></label>
<div class="col-md-6">
<div class="row">
<div class="col-md-3 nopaddingright">
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text form-control <?php echo $_streetValidationClass ?>" />
</div>
<div class="col-md-9 address_block">
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="form-control input-text <?php echo $_streetValidationClass ?>" />
<?php endfor; ?>
</div>
<div class="col-md-9 nopaddingright">
<input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="form-control input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
</div>
<div class="col-md-3 address_block">
<input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text form-control validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
<div class="col-md-12">
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text form-control <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" />
</div>
</div>
</div>
2 . i also need mobile(cell) field to be added into my form how can i add that and save into my
database.
do i need to create Custom module ? please suggest me and help me
Thank you

Related

Custom contact form gives me 404 error

I've created a custom contact form for each magento product, I've set up all the files and inserted this code inside a Magento static block:
{{block type="core/template" form_action="/PersonalizzazioniEmail/index/post/" template="catalog/product/view/form-personalizzazione.phtml"}}
Here's the form-personalizzazione.phtml
<?php $productId=$this->getRequest()->getParams();
$model = Mage::getModel('catalog/product');
$_product = $model->load($productId["id"]);
?>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="page-title">
<h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
</div>
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
<input type="hidden" id="product" name="product" value="<?php echo $_product->getName() ?>" />
<div class="fieldset">
<h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
<div class="input-box">
<input name="name" id="name" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Name')) ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
</div>
</div>
<div class="field">
<label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
<div class="input-box">
<input name="email" id="email" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Email')) ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
</div>
</div>
</li>
<li>
<label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
<div class="input-box">
<input name="telephone" id="telephone" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Telephone')) ?>" value="" class="input-text" type="text" />
</div>
</li>
<li class="wide">
<label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
<div class="input-box">
<textarea name="comment" id="comment" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Comment')) ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
</div>
</li>
</ul>
</div>
<div class="fieldset privacy">
<ul class="form-list">
<?php if (Mage::helper('privacy')->isPrivacyEnabled()): ?>
<li>
<?php echo $this->getChildHtml('privacy.include.contacts'); ?>
</li>
<?php endif;?>
</ul>
</div>
<div class="buttons-set">
<p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
<button type="submit" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Submit')) ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var contactForm = new VarienForm('contactForm', true);
//]]>
</script>
But I get a 404 error when I submit the form, what could be the reason?
Thanks
Create a Custom Contact Form in Magento,Kindly visit below URLs.
http://inchoo.net/magento/magento-email/magento-custom-email-contact-form-with-notification-system/
http://ignaciogondra.com/2015/08/24/how-to-create-a-custom-contact-form-in-magento/
If you don't want to use custom code,You can use this paid extension.
https://www.magentocommerce.com/magento-connect/custom-contact-forms.html
You can also use this Product Question,It's might be fulfilled your requirement. This is free extension.
https://www.magentocommerce.com/magento-connect/product-question-1.html
Hope It's helpful for you.

How to edit "design/frontend/base/default/ template/customer/address/edit.phtml" in magento?

<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category design
* #package base_default
* #copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
* #license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* Edit customer address template
*
* #see Mage_Customer_Block_Address_Edit
*/
?>
<?php if($this->getTitle()): ?>
<div class="page-title">
<h1><?php echo $this->getTitle() ?></h1>
</div>
<?php endif; ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="form-validate">
<div class="fieldset">
<?php echo $this->getBlockHtml('formkey')?>
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2 class="legend"><?php echo $this->__('Contact Information') ?></h2>
<ul class="form-list">
<li class="fields">
<?php echo $this->getNameBlockHtml() ?>
</li>
<li class="wide">
<label for="company"><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
</div>
</li>
<li class="fields">
<div class="field">
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
<div class="input-box">
<input type="text" name="telephone" value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" id="telephone" />
</div>
</div>
<div class="field">
<label for="fax"><?php echo $this->__('Fax') ?></label>
<div class="input-box">
<input type="text" name="fax" id="fax" title="<?php echo $this->__('Fax') ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>" />
</div>
</div>
</li>
</ul>
</div>
<div class="fieldset">
<h2 class="legend"><?php echo $this->__('Address') ?></h2>
<ul class="form-list">
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<li class="wide">
<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<li class="wide">
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php endfor; ?>
<?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
<li class="wide">
<label for="vat_id"><?php echo $this->__('VAT Number') ?></label>
<div class="input-box">
<input type="text" name="vat_id" value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>" title="<?php echo $this->__('VAT Number') ?>" id="vat_id" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>" />
</div>
</li>
<?php endif; ?>
<li class="fields">
<div class="field">
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" name="city" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
</div>
</div>
<div class="field">
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" />
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
</div>
<div class="field">
<label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
<?php echo $this->getCountryHtmlSelect() ?>
</div>
</div>
</li>
<li<?php if($this->canSetAsDefaultBilling()) echo ' class="control"' ?>>
<?php if($this->isDefaultBilling()): ?>
<strong><?php echo $this->__('Default Billing Address') ?></strong>
<?php elseif($this->canSetAsDefaultBilling()): ?>
<input type="checkbox" id="primary_billing" name="default_billing" value="1" title="<?php echo $this->__('Use as My Default Billing Address') ?>" class="checkbox" /><label for="primary_billing"><?php echo $this->__('Use as my default billing address') ?></label>
<?php else: ?>
<input type="hidden" name="default_billing" value="1" />
<?php endif; ?>
</li>
<li<?php if($this->canSetAsDefaultShipping()) echo ' class="control"' ?>>
<?php if($this->isDefaultShipping()): ?>
<strong><?php echo $this->__('Default Shipping Address') ?></strong>
<?php elseif($this->canSetAsDefaultShipping()): ?>
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1" title="<?php echo $this->__('Use as My Default Shipping Address') ?>" class="checkbox" /><label for="primary_shipping"><?php echo $this->__('Use as my default shipping address') ?></label>
<?php else: ?>
<input type="hidden" name="default_shipping" value="1" />
<?php endif; ?>
</li>
</ul>
</div>
<div class="buttons-set">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<p class="back-link"><small>« </small><?php echo $this->__('Back') ?></p>
<button type="submit" title="<?php echo $this->__('Save Address') ?>" class="button"><span><span><?php echo $this->__('Save Address') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
//]]>
</script>``
i want to when i click on button then it create pop up box with ok button and when i am click on ok button the default procedure of magento will be continue.
and all that by using different model in local code pool.
it is possible??
You could use something like that http://www.miniscript.it/demopages/confirmjquerydialog/demo.php and manage this action with jquery.
Easy, just add hidden block to the template, change default confirmation button to fake button and enable action:
<button onclick="document.getElementById('hiddendivid').style.display = 'block'; return false;">
Fake button opens div with true button
</button>
<div id="hiddendivid" style="display: none;">
this is popup div
<input type="submit" name="truemagentosubmit" value="This will real submit the form" />
<input type="submit" value="Or close thos window" onclick="document.getElementById('hiddendivid').style.display = 'none'; return false;" />
</div>
all will work in the same form like a standard submit.

warning message on joomla login form

i have used joomla login form. but when i submit empty form it display error message only for password not for user name.login form code -
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form" class="form-inline index-login">
<?php if ($params->get('pretext')) : ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
</div>
<?php endif; ?>
<div class="form-group">
<?php if (!$params->get('usetext')) : ?>
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input id="modlgn-username" type="text" name="username" class="form-control" placeholder="<?php echo JText::_('MOD_LOGIN_VALUE_USERNAME') ?>" />
<?php else: ?>
<input id="modlgn-username" type="text" name="username" class="form-control" placeholder="<?php echo JText::_('MOD_LOGIN_VALUE_USERNAME') ?>" />
<?php endif; ?>
<?php if (JPluginHelper::isEnabled('system', 'remember')) : ?>
<div class="checkbox">
<label>
<input id="modlgn-remember" type="checkbox" name="remember" class="inputbox" value="yes"/><?php echo JText::_('MOD_LOGIN_REMEMBER_ME') ?>
</label>
</div>
<?php endif; ?>
</div>
<div class="form-group">
<?php if (!$params->get('usetext')) : ?>
<input id="modlgn-passwd" type="password" name="password" class="form-control" placeholder="<?php echo JText::_('JGLOBAL_PASSWORD') ?>" />
<?php else: ?>
<label for="modlgn-passwd"><?php echo JText::_('JGLOBAL_PASSWORD') ?></label>
<input id="modlgn-passwd" type="password" name="password" class="form-control" placeholder="<?php echo JText::_('JGLOBAL_PASSWORD') ?>" />
<?php endif; ?>
<div>
<a class="forgot-password" href="<?php echo JRoute::_('index.php?option=com_users&view=reset'); ?>"><?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_PASSWORD'); ?></a></div>
</div>
<?php if (count($twofactormethods) > 1):?>
<div id="form-login-secretkey" class="control-group">
<div class="controls">
<?php if (!$params->get('usetext')) : ?>
<div class="input-prepend input-append">
<span class="add-on">
<span class="icon-star hasTooltip" title="<?php echo JText::_('JGLOBAL_SECRETKEY'); ?>">
</span>
<label for="modlgn-secretkey" class="element-invisible"><?php echo JText::_('JGLOBAL_SECRETKEY'); ?>
</label>
</span>
<input id="modlgn-secretkey" type="text" name="secretkey" class="input-small" tabindex="0" size="18" placeholder="<?php echo JText::_('JGLOBAL_SECRETKEY') ?>" />
<span class="btn width-auto hasTooltip" title="<?php echo JText::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<span class="icon-help"></span>
</span>
</div>
<?php else: ?>
<label for="modlgn-secretkey"><?php echo JText::_('JGLOBAL_SECRETKEY') ?></label>
<input id="modlgn-secretkey" type="text" name="secretkey" class="input-small" tabindex="0" size="18" placeholder="<?php echo JText::_('JGLOBAL_SECRETKEY') ?>" />
<span class="btn width-auto hasTooltip" title="<?php echo JText::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<span class="icon-help"></span>
</span>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<button type="submit" tabindex="0" name="Submit" class="btn"><?php echo JText::_('JLOGIN') ?></button>
<?php
$usersConfig = JComponentHelper::getParams('com_users'); ?>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
<?php if ($params->get('posttext')) : ?>
<div class="posttext">
<p><?php echo $params->get('posttext'); ?></p>
</div>
<?php endif; ?>
</form>

Can't use varien

In the template register.phtml I added an input type radio for some terms and condition agreements.
This one is required.
I didn't success to use the javascript Magento’s frontend validation. I add all sort of classes but nothing worked.
Is Someone knows how to do please ? thanks
Here the html
<div class="field radiobox">
<div class="input-box">
<input type="radio" name="accept" title="<?php echo $this->__('I Agree to our Terms & Conditions') ?>" id="accept" class="radio required-entry validate-one-required-by-name validation-passed validation-failed" >
<label for="accept" class=required" ><?php echo $this->__('I Agree to our Terms & Conditions') ?></label>
</div>
</div>
<script type="text/javascript">
//<![CDATA[
new Varien.FileElement('accept');
//]]>
</script>
First of all remove all class other then required-entry
<input type="radio" name="accept" title="<?php echo $this->__('I Agree to our Terms & Conditions') ?>" id="accept" class="radio required-entry" >
And put this in your form tag, you don't need to create any javascript for this just ensure that it is under form tag, in register.phtml file magento already define validation javascript so don't put your javascript again.
#Mufaddal
<div class="account-form-wrapper registerpass">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" class="ctools-use-modal-processed" novalidate="novalidate">
<div class="fieldset">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
</div>
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
<div class="field">
<label for="email_address" class="required"><em>*</em>Email Address</label>
<div class="input-box">
<input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" placeholder="<?php echo $this->__("Email Address") ?>" />
</div>
</div>
<div class="fields">
<div class="field">
<label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
<div class="input-box">
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" placeholder="Password" />
</div>
</div>
<div class="field">
<label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
<div class="input-box">
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" placeholder="Confirm Password" />
</div>
</div>
</div>
<div class="field radiobox">
<div class="input-box">
<input type="radio" name="accept" title="<?php echo $this->__('I Agree to our Terms & Conditions') ?>" id="accept" class="radio required-entry" >
<label for="accept" class=required" ><?php echo $this->__('I Agree to our Terms & Conditions') ?></label>
</div>
</div>
__('Submit') ?>" id="form-submit">
__('maak mijn profiel aan') ?>
</form>

Magento newsletter auto checked on registration Page

I'm running magento 1.7.0.2 and I want the checkbox of the newsletter subscription on the registration page checked by default. I have followed a few hacks but they were all written for older versions of magento.
Here's a link to one of the hacks which I tried and didn't work: Force newsletter subscription in Magento
Any help is greatly appreciated!
<div class="account-create">
<div class="page-title">
<h1><?php echo $this->__('Complete your profile') ?></h1>
</div>
<?php echo $this->getChildHtml('form_fields_before')?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.extra')?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<div class="fieldset">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
<ul class="form-list">
<li class="fields">
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
</li>
<li>
<label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
</div>
</li>
<?php if ($this->isNewsletterEnabled()): ?>
<li class="control">
<div class="input-box">
<li>
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed" <?php if($this->getFormData()->getIsSubscribed()){ ?> checked="checked"<?php }elseif($this->getFormData()->getIsSubscribed == NULL){ ?> checked="checked"<?php }?> />
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
</li>
</div>
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.newsletter')?>
</li>
<?php endif ?>
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
<?php if ($_dob->isEnabled()): ?>
<li><?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?></li>
<?php endif ?>
<?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
<?php if ($_taxvat->isEnabled()): ?>
<li><?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?></li>
<?php endif ?>
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
<?php if ($_gender->isEnabled()): ?>
<li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
<?php endif ?>
</ul>
</div>
<?php if($this->getShowAddressFields()): ?>
<div class="fieldset">
<input type="hidden" name="create_address" value="1" />
<h2 class="legend"><?php echo $this->__('Address Information') ?></h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="company"><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" name="company" id="company" value="<?php echo $this->escapeHtml($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
</div>
</div>
<div class="field">
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
<div class="input-box">
<input type="text" name="telephone" id="telephone" value="<?php echo $this->escapeHtml($this->getFormData()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" />
</div>
</div>
</li>
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<li class="wide">
<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<li class="wide">
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php endfor; ?>
<li class="fields">
<div class="field">
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
</div>
</div>
<div class="field">
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
</div>
<div class="field">
<label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
<?php echo $this->getCountryHtmlSelect() ?>
</div>
</div>
</li>
</ul>
<input type="hidden" name="default_billing" value="1" />
<input type="hidden" name="default_shipping" value="1" />
</div>
<?php endif; ?>
<div class="fieldset">
<h2 class="legend"><?php echo $this->__('Login Information') ?></h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
<div class="input-box">
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</div>
</div>
<div class="field">
<label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
<div class="input-box">
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</div>
</div>
</li>
<?php echo $this->getChildHtml('form.additional.info'); ?>
</ul>
</div>
<div class="buttons-set">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<p class="back-link"><small>« </small><?php echo $this->__('Back') ?></p>
<button type="submit" title="<?php echo $this->__('Submit') ?>" class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
Here is what worked for me. If you want the newsletter opt in on the customer account registration page checked by default, get this file:
/app/design/frontend/your_theme/default/template/customer/form/regist‌​er.phtml
Find this line:
<?php if ($this->isNewsletterEnabled()): ?>
Right below it, add this:
<?php
$checked = true;
if($this->getFormData()->getEmail()) {
if(!$this->getFormData()->getIsSubscribed()) {
$checked = true;
}
}
?>
Then Find this div
<div class="input-box">
Replace the code in the div with this code:
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed" checked="checked" class="checkbox" />
That's it! Save and upload the file.
Please find the following code in register.phtml file:
<?php if ($this->isNewsletterEnabled()): ?>
<li class="control">
<div class="input-box">
<li>
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed" <?php if($this->getFormData()->getIsSubscribed()){ ?> checked="checked"<?php }elseif($this->getFormData()->getIsSubscribed == NULL){ ?> checked="checked"<?php }?> />
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
</li>
</div>
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.newsletter')?>
</li>
<?php endif ?>
And Replace with the following code :
<?php if ($this->isNewsletterEnabled()): ?>
<?php
$checked = true;
if($this->getFormData()->getEmail()) {
if(!$this->getFormData()->getIsSubscribed()) {
$checked = false;
}
}
?>
<li class="control">
<div class="input-box">
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($checked): ?> checked="checked"<?php endif; ?> class="checkbox" />
</div>
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.newsletter')?>
</li>
<?php endif ?>
I have used php for this because. by this we can get user preference after user submit
form and error occur
Hope this Help !!
Please Add the following code in register.phtml file:
Add chaked End of line Input type
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" checked />

Resources