Hi,
This is my first attempt of creating a new item Form.
In my CreateForm I have this:
<?php
class ProjectName_Form_ItemCreate extends Zend_Form
{
public function init()
{
// initialize form
$this->setAction('/catalog/item/create')
->setMethod('post');
// create text input for name
$name = new Zend_Form_Element_Text('FirstName');
$name->setLabel('Name:')
->setOptions(array('size' => '35'))
->setRequired(true)
->addValidator('Regex', false, array(
'pattern' => '/^[a-zA-Z]+[A-Za-z\'\-\. ]{1,50}$/' ))
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for surname
$lastname = new Zend_Form_Element_Text('LastName');
$lastname->setLabel('Last Name:')
->setOptions(array('size' => '35'))
->setRequired(true)
->addValidator('Regex', false, array(
'pattern' => '/^[a-zA-Z]+[A-Za-z\'\-\. ]{1,50}$/'
))
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for password
$password = new Zend_Form_Element_Password('Password');
$password->setLabel('Password:')
->setOptions(array('size' => '30'))
->setRequired(true)
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for email
$email = new Zend_Form_Element_Text('Email');
$email->setLabel('Email address:');
$email->setOptions(array('size' => '50'))
->setRequired(true)
->addValidator('Email', false, array(
'messages'=> array(
Zend_Validate_EmailAddress::INVALID
=>"ERROR: Invalid email address",
Zend_Validate_EmailAddress::INVALID_FORMAT
=>"ERROR: Invalid email address",
Zend_Validate_EmailAddress::INVALID_HOSTNAME
=>"ERROR: Invalid hostname format",
Zend_Validate_EmailAddress::INVALID_LOCAL_PART
=>"ERROR: Invalid username format",
Zend_Validate_EmailAddress::LENGTH_EXCEEDED
=>"ERROR: Email address too long"
)
))
->addFilter('StringTrim');
// create text input for tel number
$tel = new Zend_Form_Element_Text('TelNo');
$tel->setLabel('Telephone number:');
$tel->setOptions(array('size' => '50'))
->addValidator('StringLength', false, array('min' => 8))
->addValidator('Regex', false, array(
'pattern' => '/^\+[1-9][0-9]{6,30}$/',
'messages' => array(
Zend_Validate_Regex::INVALID =>
'\'%value%\' does not match international number format
+XXYYZZZZ',
Zend_Validate_Regex::NOT_MATCH =>
'\'%value%\' does not match international number format
+XXYYZZZZ')
))
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for mobile number
$mobtel = new Zend_Form_Element_Text('MobileNo');
$mobtel->setLabel('Telephone number:');
$mobtel->setOptions(array('size' => '50'))
->addValidator('StringLength', false,
array('min' => 8))
->addValidator('Regex', false, array(
'pattern' => '/^\+[1-9][0-9]{6,30}$/',
'messages' => array(
Zend_Validate_Regex::INVALID =>
'\'%value%\' does not match
international number format
+XXYYZZZZ',
Zend_Validate_Regex::NOT_MATCH =>
'\'%value%\' does not match international number format
+XXYYZZZZ' )
))
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for address1
$address = new Zend_Form_Element_Textarea('Address1');
$address->setLabel('Address 1:')
->setOptions(array('rows' => '6','cols' => '36'))
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create text input for Postcode
$postcode = new Zend_Form_Element_Text('PostCode');
$postcode->setLabel('PostCode:')
->setRequired(true)
->addFilter('HtmlEntities')
->addFilter('StringTrim');
// create select input for item country
$country = new Zend_Form_Element_MultiSelect('Country');
$country->setLabel('Country:')
->setMultiOptions (array(
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
....................................
'ZW' => 'Zimbabwe', ));
// create checkbox for newsletter
$newsletter = new Zend_Form_Element_Checkbox('Newsletter');
$newsletter->setLabel('Subscribe to Newsletter');
// ->setCheckedValue=>(TRUE)
->setUncheckValue=>(FALSE)
->setDecorators($this->elementDecorators);
// create submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit Entry')
// ->setOrder(100)
->setOptions(array('class' => 'submit'));
// attach elements to form
$this->addElement($name)
->addElement($lastName)
->addElement($password)
->addElement($email)
->addElement($address1)
->addElement($town)
->addElement($country)
->addElement($Postcode)
->addElement($TelNo)
->addElement($MobileNo)
->addElement($newsletter);
// create display group for seller information
// $this->addDisplayGroup(array('FirstName', 'Last Name', 'Email',
'TelNo', 'MobileNo','Address1', 'Country', 'Postcode','TelNo',
'MobileNo',Newsletter'), 'contact');
// $this->getDisplayGroup('contact')
// ->setOrder(10)
// ->setLegend('User Information');
}
}
=================================================================
It says I have an error syntax error, unexpected T_OBJECT_OPERATOR where the
bold is down here.But I am assuming there is more than one error. Sorry this
is my first attempt on building a project with Zend.
Can some please indicatte what is the bug?
//Create checkbox for newsletter
$newsletter = new Zend_Form_Element_Checkbox('Newsletter');
$newsletter->setLabel('Subscribe to Newsletter');
->setCheckedValue=>('1')
->setUncheckValue=>('0')
->setDecorators($this->elementDecorators);
when I uncomment it I get another error
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Error-message-on-a-create-form-tp3381361p3381361.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]