I have a custom payment method I've implemented and it has a form that looks something like this:
<div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
<div>
<label for="<?php echo $_code ?>_method_no"><?php echo $this->__('Method No') ?>*</label>
<span>
<select id="<?php echo $_code ?>_method_no" name="payment[method_no]"
class="dropdown validate-select payment-type-select"
value="<?php echo $this->htmlEscape($this->getInfoData('method_no')) ?>">
<option value=""><?php echo $this->__('--Please Select--') ?></option>
<option title="<?php echo $this->__('Method One') ?>" value="1">Method One</option>
<option title="<?php echo $this->__('Method Two') ?>" value="2">Method Two</option>
<option title="<?php echo $this->__('Method Three') ?>" value="3">Method Three</option>
</select>
</span>
</div>
</div>
<div>
<?php echo $this->getMethod()->getConfigData('message'); ?>
</div>
My question is, how do I validate this in my model validate function? I know that I have validation on the front end with the class validate-select
but I would like to know how I can check the value in the validate function. I have something like this right now but it is not working:
<?php
class Name_Mypaymentmethod_Model_Standard extends Mage_Payment_Model_Method_Abstract {
protected $_code = 'mypaymentmethod';
protected $_isInitializeNeeded = true;
protected $_canUseInternal = true;
protected $_canUseForMultishipping = false;
protected $_formBlockType = 'mypaymentmethod/form';
protected $_infoBlockType = 'mypaymentmethod/info';
public function getOrderPlaceRedirectUrl() {
return Mage::getUrl('mypaymentmethod/payment/redirect', array('_secure' => true));
}
public function assignData($data) {
$info = $this->getInfoInstance();
if ($data->getMethodNo())
{
$info->setMethodNo($data->getMethodNo());
}
return $this;
}
public function validate() {
parent::validate();
$info = $this->getInfoInstance();
if (!$info->getMethodNo())
{
$errorCode = 'invalid_data';
$errorMsg = $this->_getHelper()->__("Please select a method.\n");
}
if ($errorMsg)
{
Mage::throwException($errorMsg);
}
return $this;
}
}
?>
It seems like the $info->getMethodNo()
function is not working for my select dropdown. How do I get the value? I've been looking through forums, tutorials, posts for the last couple hours and can't find anything that shows validating a select dropdown like this.
Any help would be appreciated! Thanks