本文整理汇总了PHP中Zend_Form::populate方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::populate方法的具体用法?PHP Zend_Form::populate怎么用?PHP Zend_Form::populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form
的用法示例。
在下文中一共展示了Zend_Form::populate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nodeForm
/**
* Hook for node form, add extra fields
*
* @param Zend_Form $form
* @param array $arguments
*/
public function nodeForm(Zend_Form &$form, &$arguments)
{
$item =& array_shift($arguments);
$content_type = Zoo::getService('content')->getType($item->type);
if ($content_type->has_parent_url == 0) {
$path = new Zend_Form_Element_Text('rewrite_path', array('size' => 65));
$path->setLabel('URL');
$form->addElement($path);
$options = array('legend' => Zoo::_("URL Rewriting"));
$form->addDisplayGroup(array('rewrite_path'), 'rewrite_path_options', $options);
if ($item->id > 0) {
$factory = new Rewrite_Path_Factory();
$path = $factory->find($item->id)->current();
if ($path) {
$form->populate(array('rewrite_path' => $path->path));
} else {
// Find parent's path
if ($item->pid && ($path = $factory->find($item->pid)->current())) {
$form->populate(array('rewrite_path' => $path->path . "/" . $item->id));
} else {
$form->populate(array('rewrite_path' => $item->url()));
}
}
}
}
}
示例2: ajouterAction
public function ajouterAction()
{
$form = new Zend_Form();
$form->setMethod('post');
$form->addElement('text', 'TITRE_E', array('label' => 'Titre de l\'émission : ', 'required' => true, 'filters' => array('StringTrim')));
$form->addElement('text', 'THEME', array('label' => 'Theme : ', 'required' => true, 'filters' => array('StringTrim')));
$form->addElement('text', 'ANIMATEURS', array('label' => 'Animateur(s) : ', 'required' => true, 'filters' => array('StringTrim')));
$form->addElement('text', 'DUREE', array('label' => 'Durée de l\'émission : ', 'required' => true, 'filters' => array('Int')));
$form->addElement('text', 'PATH_E', array('label' => 'Lien vers le podcast : ', 'required' => false, 'filters' => array('StringTrim')));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Ajouter');
$form->addElement($submit);
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$dba = Zend_Registry::get('dba');
$datas = array('THEME' => $formData["THEME"], 'ANIMATEURS' => $formData["ANIMATEURS"], 'DUREE' => $formData["DUREE"], 'TITRE_E' => $formData["TITRE_E"], 'PATH_E' => $formData["PATH_E"]);
$dba->beginTransaction();
try {
$dba->insert('EMISSION', $datas);
$dba->commit();
} catch (Exception $e) {
$dba->rollBack();
echo $e->getMessage();
}
$this->_helper->redirector('index');
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
示例3: createForm
/**
* Create the setting form and populate with the custom setting values
*
* @param integer $groupid
*/
public static function createForm($groupid)
{
$form = new Zend_Form(array('action' => '/admin/settings/index/groupid/' . $groupid, 'method' => 'post'));
$form->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
$records = Doctrine_Query::create()->from('SettingsParameters s')->where('group_id = ?', $groupid)->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
if (!empty($records)) {
foreach ($records as $record) {
// Custom style added to the textareas
$style = $record['type'] == "textarea" ? array('rows' => 4) : array();
$form->addElement($record['type'], $record['var'], $style + array('decorators' => array('Bootstrap'), 'filters' => array('StringTrim'), 'label' => $record['name'], 'description' => $record['description'], 'class' => 'form-control obj_' . $record['var']));
if (!empty($record['config'])) {
$config = json_decode($record['config'], true);
if (!empty($config['class']) && class_exists($config['class']) && !empty($config['method']) && method_exists($config['class'], $config['method'])) {
$class = $config['class'];
$method = $config['method'];
$data = call_user_func(array($class, $method));
if (!empty($data)) {
if ($record['type'] == "select") {
$form->getElement($record['var'])->setMultiOptions($data);
} else {
$form->getElement($record['var'])->setValue($data);
}
}
}
}
}
}
$settings = self::getValues(Settings::find_by_GroupId($groupid));
$form->populate($settings);
return $form;
}
示例4: populateFromModel
public function populateFromModel($id)
{
$row = $this->_model->find($id)->current();
if ($row) {
parent::populate($row->toArray());
}
}
示例5: editAction
public function editAction()
{
$configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
$userForm = new Zend_Form($configForm->user);
$userId = $this->getRequest()->getParam('id', null);
if ($this->getRequest()->isPost()) {
if ($userForm->isValid($_POST)) {
try {
$values = $userForm->getValues();
unset($values['password_repeat']);
$userId = $this->userRepository->saveEntity($values);
$this->_helper->systemMessages('notice', 'Nutzer erfolgreich gespeichert');
} catch (\Exception $e) {
$log = $this->getInvokeArg('bootstrap')->log;
$log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
$this->_helper->systemMessages('error', 'Nutzer konnte nicht gespeichert werden');
}
}
} else {
try {
$entity = $this->userRepository->fetchEntity($userId);
$userForm->populate($entity->toArray());
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 404);
}
}
$userForm->setAction('/admin/user/edit/' . $userId);
$this->view->form = $userForm;
}
示例6: nodeForm
/**
* Hook for node form - if type is Guestbook Node, add extra fields
*
* @param Zend_Form $form
* @param array $arguments
*/
public function nodeForm(Zend_Form &$form, &$arguments)
{
$item =& array_shift($arguments);
if ($item->type == "guestbook_entry") {
// Add guestbook fields
$name = new Zend_Form_Element_Text('guestbook_name', array('size' => 35));
$name->setLabel('Name');
$name->setRequired(true);
$email = new Zend_Form_Element_Text('guestbook_email', array('size' => 35));
$email->setLabel('Email');
$email->setRequired(true)->addValidator(new Zend_Validate_StringLength(6))->addValidator(new Zend_Validate_EmailAddress());
$url = new Zend_Form_Element_Text('guestbook_homepage', array('size' => 35));
$url->setLabel('Homepage');
$url->setRequired(false)->addValidator(new Zend_Validate_StringLength(4))->addValidator(new Zend_Validate_Hostname());
$form->addElements(array($name, $email, $url));
$options = array('legend' => Zoo::_("Guest information"));
$form->addDisplayGroup(array('guestbook_name', 'guestbook_email', 'guestbook_homepage'), 'guestbook_add', $options);
if ($item->id > 0) {
// Fetch guestbook object
$factory = new Guestbook_Node_Factory();
$guestbook = $factory->find($item->id)->current();
if (!$guestbook) {
$guestbook = $factory->createRow();
}
$values = $guestbook->toArray();
$populate = array();
foreach ($values as $key => $value) {
$populate['guestbook_' . $key] = $value;
}
$form->populate($populate);
}
}
}
示例7: populate
public function populate(array $dados)
{
$this->getElement('Cadastrar')->setName('Editar');
if (isset($dados['preco']) && $dados['preco']) {
$dados['preco'] = number_format($dados['preco'], 2, ',', '.');
$dados['preco'] = str_replace('.', '', $dados['preco']);
}
return parent::populate($dados);
}
示例8: saveComment
private function saveComment(Zend_Form $form, GC\Entity\BlogEntry $blogEntry)
{
$comment = new GC\Entity\Comment($form->getValues());
$comment->blogEntry = $blogEntry;
$this->_em->persist($comment);
$this->_em->flush();
// clear form values
$form->populate(array('name' => '', 'email' => '', 'content' => ''));
}
示例9: testPopulateProxiesToSetDefaults
public function testPopulateProxiesToSetDefaults()
{
$this->testCanAddAndRetrieveMultipleElements();
$values = array('foo' => 'foovalue', 'bar' => 'barvalue', 'baz' => 'bazvalue', 'bat' => 'batvalue');
$this->form->populate($values);
$test = $this->form->getValues();
$elements = $this->form->getElements();
foreach (array_keys($values) as $name) {
$this->assertEquals($values[$name], $test[$name]);
}
}
示例10: indexAction
public function indexAction()
{
$session = new \Zend_Session_Namespace('twitter', true);
$oauthConfig = array('callbackUrl' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'siteUrl' => 'http://twitter.com/oauth');
$configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
$twitterApiForm = new \Zend_Form($configForm->twitterApi);
if ($this->getRequest()->isPost()) {
if ($twitterApiForm->isValid($_POST)) {
try {
$this->twitterRepository->saveEntity($twitterApiForm->getValues());
$oauthConfig['consumerKey'] = $twitterApiForm->getValue('consumerKey');
$oauthConfig['consumerSecret'] = $twitterApiForm->getValue('consumerSecret');
$consumer = new \Zend_Oauth_Consumer($oauthConfig);
$token = $consumer->getRequestToken();
$session->twitterRequestToken = serialize($token);
$consumer->redirect();
} catch (\Exception $e) {
$log = $this->getInvokeArg('bootstrap')->log;
$log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
$this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
}
}
} else {
try {
$entity = $this->twitterRepository->fetchEntity();
if ($entity) {
if (isset($session->twitterRequestToken)) {
$oauthConfig['consumerKey'] = $entity->consumerKey;
$oauthConfig['consumerSecret'] = $entity->consumerSecret;
$consumer = new \Zend_Oauth_Consumer($oauthConfig);
$token = $consumer->getAccessToken($_GET, unserialize($session->twitterRequestToken));
$this->twitterRepository->saveEntity(array('accessToken' => serialize($token)));
unset($session->twitterRequestToken);
$this->_helper->systemMessages('notice', 'Einstellungen erfolgreich gespeichert');
}
$twitterApiForm->populate($entity->toArray());
}
} catch (\Exception $e) {
$log = $this->getInvokeArg('bootstrap')->log;
$log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
$this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
}
}
$twitterApiForm->setAction('/admin/twitter');
$this->view->form = $twitterApiForm;
}
示例11: nodeForm
/**
* Hook for node form - if type is Estate Node, add extra fields
*
* @param Zend_Form $form
* @param array $arguments
*/
public function nodeForm(Zend_Form &$form, &$arguments)
{
$item =& array_shift($arguments);
$title = new Zend_Form_Element_Text('title', array('class' => 'content_title'));
$title->setLabel('Title');
$title->setRequired(true)->addValidator(new Zend_Validate_StringLength(2, 255));
$content = new Zoo_Form_Element_Wysiwyg('content');
$content->setRequired(false)->setLabel('Content')->setAttrib('cols', 50);
$form->addElements(array($title, $content));
$form->addDisplayGroup(array('title', 'content'), 'content_add', array('legend' => Zoo::_('Content')));
if (Zend_Auth::getInstance()->hasIdentity()) {
$identity = Zend_Auth::getInstance()->getIdentity();
$uid = $identity->id;
} else {
$uid = 0;
}
$filters = Zoo::getService('filter')->getFiltersByUser($uid);
if ($filters && $filters->count() > 0) {
foreach ($filters as $filter) {
$options = array();
if (!$filter->optional) {
$options = array('disabled' => 'disabled', 'value' => 1);
} elseif ($item->id == 0) {
$options['value'] = $filter->default;
}
$ele = new Zend_Form_Element_Checkbox("filter_" . $filter->name, $options);
$ele->setLabel($filter->name);
$form->addElement($ele);
$elements[] = "filter_" . $filter->name;
$userfilters[$filter->id] = $filter;
}
$options = array('legend' => Zoo::_("Filters"));
$form->addDisplayGroup($elements, 'filter_set', $options);
if ($item->id > 0) {
// Fetch set filters
$filters = Zoo::getService('content')->getFilters($item);
$populate = array();
foreach ($filters as $filter) {
$populate['filter_' . $userfilters[$filter->filter_id]->name] = 1;
}
$form->populate($populate);
}
}
}
示例12: indexAction
public function indexAction()
{
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$this->_redirect("/accueil");
// echo "identity remove";
// $auth->clearIdentity();
}
$this->view->menu = "index";
$form = new Zend_Form();
$form->setMethod('post');
$form->addElement('text', 'LOGIN', array('label' => 'Login : ', 'required' => true, 'filters' => array('StringTrim')));
$form->addElement('password', 'PASSWORD', array('label' => 'Password : ', 'required' => true, 'filters' => array('StringTrim')));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Se Connecter')->setAttrib('class', 'valid_button gros-bouton');
$form->addElement($submit);
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
MyAcl::setCache(Zend_Cache::factory("Core", "File"));
$acl = MyAcl::getInstance();
Acl_Db_Table_Row::setAcl($acl);
$dba = Zend_Registry::get('dba');
$TMembres = new Application_Model_Membre($dba);
$membre = $TMembres->createRow();
$membre->LOGIN = $formData["LOGIN"];
// ceci pourrait provenir d'un formulaire
$membre->PASSWORD = $formData["PASSWORD"];
// ceci pourrait provenir d'un formulaire
$result = $membre->authenticate();
// si OK : persistance 30min en session
if (!$result->isValid()) {
echo 'login ou mot de passe incorrect';
} else {
echo "ok";
$this->_redirect("/accueil");
}
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
示例13: indexAction
/**
* Initiate system installation
*
*/
public function indexAction()
{
$settingsform = new Zoo_Form_Settings();
$modulesform = new Zoo_Form_Modules();
$form = new Zend_Form(array('name' => 'installForm'));
$form->setSubFormDecorators(array('FormElements', 'Fieldset'));
$form->addSubForm($settingsform, 'settings');
$form->addSubForm($modulesform, 'modules');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($settingsform->isValid($formData)) {
// $this->_forward('install');
}
$form->populate($formData);
}
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Install');
$form->addElements(array($submit));
$this->view->form = $form;
}
示例14: indexAction
public function indexAction()
{
$configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
$deliciousApiForm = new \Zend_Form($configForm->deliciousApi);
if ($this->getRequest()->isPost()) {
if ($deliciousApiForm->isValid($_POST)) {
try {
$this->deliciousRepository->saveEntity($deliciousApiForm->getValues());
$this->_helper->systemMessages('notice', 'Einstellungen erfolgreich gespeichert');
} catch (\Exception $e) {
$log = $this->getInvokeArg('bootstrap')->log;
$log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
$this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
}
}
} else {
$entity = $this->deliciousRepository->fetchEntity();
if ($entity) {
$deliciousApiForm->populate($entity->toArray());
}
}
$deliciousApiForm->setAction('/admin/delicious');
$this->view->form = $deliciousApiForm;
}
示例15: populateForm
/**
* Hook for setting the data on the form.
*/
protected function populateForm()
{
$this->_form->populate($this->formData);
}