Hi I am working on a custom module form in Magento. I have used the default validation given by Magento.
Here is my form and passing form id to varienform
<form id="my-custom-form" action="" method="post">
<label> Form</label>
<label>First Name</label>
<strong>:</strong>
<input class="input-text required-entry" type="text" name="fname" maxlength="20"><br>
<label>Last Name</label>
<strong>:</strong>
<input class="input-text required-entry" type="text" name="lname" maxlength="20"><br>
<label>Address</label>
<strong>:</strong>
<textarea class="required-entry" placeholder="Type your address" name="address"></textarea><br>
<label>State</label>
<strong>:</strong>
<input class="required-entry" type="text" maxlength="20" name="state"><br>
<label>City</label>
<strong>:</strong>
<input class="required-entry" type="text" maxlength="20" name="city"><br>
<label>Mobile No</label>
<strong>:</strong>
<input class="required-entry" type="number" maxlength="10" name="mobileno"> <br>
<input type="submit" name="submit" value="submit">
<input type="button" name="Cancel" value="cancel">
</form>
<script type="text/javascript">
//< ![CDATA[
var customForm = new VarienForm('my-custom-form');
//]]>
</script>
I have added the db insert in indexcontroller
<?php
class MyCustom_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
/*
* this method privides default action.
*/
public function indexAction()
{
$param = $this->getRequest()->getParams();
$firstname = $param['fname'];
$lastname = $param['lname'];
$address = $param['address'];
$state = $param['state'];
$city = $param['city'];
$mobile = $param['mobileno'];
$model = Mage::getModel('helloworld/helloworld');
// $model->setTitle($title);
$model->setFirstname($firstname);
$model->setLastname($lastname);
$model->setAddress($address);
$model->setState($state);
$model->setCity($city);
$model->setMobileno($mobile);
$model->save();
/*
* Initialization of Mage_Core_Model_Layout model
*/
$this->loadLayout();
/*
* Building page according to layout confuration
*/
$this->renderLayout();
}
}
When I run my module the form appears and when I add no values and click submit the validation errors are getting displayed so no problem with validation but when I checked into db the tables are getting updated with null values. What could be the reason ?