How to make middle name required in magento customer entity?
There is option in System->Configuration->Customer configuration, but it's optional.
To make your Middle Name field Required open the following file:
/app/design/frontend/default/[YOURTHEME]/template/customer/widget/name.phtml
or if it doesn't exist there, open:
/app/design/frontend/base/default/template/customer/widget/name.phtml
Look for the following code:
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text" <?php echo $this->getFieldParams() ?> />
Where it says class="input-text" make it say class="input-text required-entry"
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text required-entry" <?php echo $this->getFieldParams() ?> />
It's toward the end of the line. Look at the other code in the file as well-- they all have the same class.
Related
Guys I am stuck here in Codeigniter validation. The scenario is that I want to display all the error messages right below each respective input field and not all the error messages together on the top of the form. Could anyone help me, how to do this?
Check below mentioned code. This will help you.
<h5>Username</h5>
<?php echo form_error('username'); ?>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<h5>Password</h5>
<?php echo form_error('password'); ?>
<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />
<h5>Password Confirm</h5>
<?php echo form_error('passconf'); ?>
<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />
<h5>Email Address</h5>
<?php echo form_error('email'); ?>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />
Use form_error() function to do that. As describe in manual
echo form_error('username');
All you have to do is put this line under the field where you want to see error message. Here username is the name of the form field
more details
https://www.codeigniter.com/user_guide/libraries/form_validation.html#showing-errors-individually
write below code after your text or drop-down field
<?php echo form_error('field_name','<div class="errorClass">','</div>');?>
this here is part of our magento shop system code:
<label for="qty_<?php echo $_product->getId(); ?>"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/3/')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
I will add the functionality that I can add more products into the cart with on click. This works when I will add an parameter to this code: setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/3/'). My change is qty/3/
But this is static. Instead of the 3, I will put here the value of name="qty_<?php echo $_product->getId(); ?>".
I have no idea how this can work.
<!-- line breaks are for legibility, you can put on one line if you prefer -->
<button type="button"
title="<?php echo $this->__('Add to Cart') ?>"
class="button btn-cart"
onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/'
+ $F('qty_<?php echo $_product->getId() ?>'))">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>
I used the $F() shorthand to get the value of an element. It's only parameter is the name of an input, and that is the "qty_<?php echo $_product->getId() ?>" you knew you had to use somewhere.
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
In MAGENTO,When viewing products in the category view, I would like to be able to have a “Quantity” box that allows the user to enter the quantity needed before clicking the “Add to Cart” button. How can I show this?
In List.phtml file find the below line
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
and replace it with
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
I'm trying to get my Upsell products, which I use instead of related products on the view.phtml, to work with a Quantity field in front of the Add to cart button. I'am also using AheadWorks Ajax AddToCart Pro 2.5 extension.
Right now, I'am adding the products without quantity fields with this snippet:
<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form>
This works great, but I cannot change the quantity due to the lacking quantity field. Then I try to use this from my list.phtml which works fine, in the category view:
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
Now, the funny thing is, this does not work if I try to use it in upsell.phtml, but I cannot figure out why? This works perfect with Ajax Cart Pro from AW in the Category view's.
In upsell.phtml the product object is called $_link per the following code:
<?php if($_link=$this->getIterableItem()): ?>
If you're trying to include your code in your upsell.phtml then you'll have to change $_product to $_link like this:
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_link->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
It should go after the following line:
<?php if($_link=$this->getIterableItem()): ?>