First of all: have you considered sending the two forms to two different actions? That way you can handle each form separately in an action each. This should be the "best-pratice" if you're using the Zend MVC component.
The other option is to check for the value of the submit button which will be included in the request, e.g.
<input type="submit" name="save" value="form1" />
// in PHP:
// $_POST["save"] will contain "form1"
<input type="submit" name="save" value="form2" />
// in PHP:
// $_POST["save"] will contain "form2"
Be careful as the value
-attribute will be rendered as the button's label.
So perhaps you want to distingush the forms by different submit-button names:
<input type="submit" name="save-form1" value="Submit" />
// in PHP:
// $_POST["save-form1"] will contain "Submit"
<input type="submit" name="save-form2" value="Submit" />
// in PHP:
// $_POST["save-form2"] will contain "Submit"
EDIT:
During the comment-dialog between the OP and myself the following seems to be a possible solution:
class My_Form_Base extends Zend_Form
{
private static $_instanceCounter = 0;
public function __construct($options = null)
{
parent:: __construct($options);
self::$_instanceCounter++;
$this->addElement('hidden', 'form-id',
sprintf('form-%s-instance-%d', $this->_getFormType(), self::$_instanceCounter);
}
protected _getFormType()
{
return get_class($this);
}
}
class My_Form_Type1 extends My_Form_Base
{
public function init()
{
// more form initialization
}
}
class My_Form_Type2 extends My_Form_Base
{
public function init()
{
// more form initialization
}
}