I have created a simple product selector. In the phtml, I created a form that post data and these data are received by controller to be validated before registering to a registry.
I also have product collection that gets the data to be filter coming from the registry. I have several filters and if one fails, the system should display a message.
This is what I have done so far.
My Controller:
public function indexAction() {
if ($data = $this->getRequest()->getPost()) {
$data['ta'] = $this->getRequest()->getPost('torqueAction');
$data['tr'] = $this->getRequest()->getPost('torqueRequired');
$data['tm'] = $this->getRequest()->getPost('torqueMetric');
$data['tmax'] = $data['tr'] / 80 * 100;
if (validation is equal to true) {
Mage::register('t-action', $data['ta']);
Mage::register('t-req', $data['tr']);
Mage::register('t-metric', $data['tm']);
Mage::register('t-max', $data['tmax']);
$this->_redirect('productselector/index/result');
}else {
// Display message about the error
}
}
}
My Collection located in the phtml:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addFieldTofilter($attr_name, array(
'eq' => Mage::getResourceModel('catalog/product')
->getAttribute($attr_name)
->getSource()
->getOptionId($attr_val)
))
->addAttributeToSelect('*')
->addFieldTofilter($metric, array('gteq' => $metric_val_min))
->addFieldTofilter($metric, array('lteq' => $metric_val_max))
->load();
if ($collection == NULL) { // not sure how to validate it if one filter fails
echo "sorry, no product available";
}else {
//Display some errors
}
QUESTIONS:
How to validate form post in the controller and checks if empty and no malicious code?
How to check product collection if one filter was not met?
How do I display these errors from controller and product collection?
Thanks