Validate your magento form using button



<form method="post" id="login-form" name="login_form">
/* here goes form field */</code></div>
<div><button type="button" onclick="if(dataForm.validator && dataForm.validator.validate())</div>
<div>{ ajaxRequest();}"class="button" title="<?php echo $this->__('Login') ?>"
name="send" id="send2"><?php echo $this->__('Login') ?></button>
</form><script type="text/javascript">
function ajaxRequest()
{
/* Here your ajax code
}
</script>/*This is validation script*/
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
</script>

Create your own session namespace for storing your custom session variable


First, make sure you have your own custom module if not then create.

and make session.php file in model folder of your module and write down below code in it.

 <?php
class <namespace>_<module>_Model_Session extends Mage_Core_Model_Session_Abstract
{public function __construct() {

$namespace = 'mysession';

$this->init($namespace);
Mage::dispatchEvent('myapp_session_init', array('myapp_session' => $this));
}

}
and then now you can store session variable like
// Set the "foo" variable
Mage::getSingleton("myapp/session")->setFoo("bar");
// Same thing
Mage::getSingleton("myapp/session")->setData("foo", "bar");// Another example. Let's say we want to name our variable "foo_bar"
Mage::getSingleton("myapp/session")->setFooBar("data");
// or
Mage::getSingleton("myapp/session")->setData("foo_bar", "bar");

// Get data the same way
Mage::getSingleton("myapp/session")->getFoo()
// or
Mage::getSingleton("myapp/session")->getData("foo");</div>
<div>
]
you can see output if you print array
 [Mysession] => Array
(
[_session_validator_data] => Array
(
[remote_addr] => 192.168.1.100
[http_via] =>
[http_x_forwarded_for] =>
[http_user_agent] => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0
)[session_hosts] => Array
(
[192.168.1.100] => 1
)

[foo] => bar
)

)

How to add customer dashboard tab at fronside?


first of all create one phtml file that contain your content at customer/account/dashboard/product.phtml

then in customer.xml add below code

<customer_account_myproduct translate="label">
 <label>Customer Payment Edit Form</label>
 <update handle="customer_account"/>
 <reference name="content">
 <block type="core/template" name="payment_info" as="payment_info" output="" template="customer/account/dashboard/product.phtml"/>
 </reference>
 </customer_account_myproduct>
Then add link for that page
<reference name="left">
 <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
 <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
 <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
 <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
 <action method="addLink" translate="label" module="customer"><name>my_product</name><path>customer/account/myproduct/</path><label>My Product</label></action></code></code></block>
 <remove name="tags_popular"/>
 <remove name="leftnav" />
 <remove name="left.permanent.callout" />
 </reference>
and then in Accountcontroller give Action for render layout
public function myproductAction()
 {$this->loadLayout();
 $this->getLayout()->getBlock('head')->setTitle($this->__('My Product'));
 $this->renderLayout();
 }
Happy Codding 🙂

To set cms page link in top navigation and set them active when clik on them.below is code for the same.


For set link

<ul id="nav">
 <?php echo $_menu ?>
 <li id="cms_page" onclick="addClass(this.id);"><a class="fancyboxclass1"
href="<?php  echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'testpop';?>">select</a></li>
 </ul>
for set link active when click on them
function addClass(id){
$$('li.active').invoke('removeClassName','active');
node = $(id);
node.addClassName("active");
}