本文整理汇总了PHP中Zend\Form\Form::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getData方法的具体用法?PHP Form::getData怎么用?PHP Form::getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate($data)
{
$this->form->setData($data);
$isValid = $this->form->isValid();
$normalized = $this->form->getData();
unset($normalized['ViewReportControl']);
$validated = new \SSRS\Form\ValidateResult();
$validated->isValid = $isValid;
$validated->parameters = $normalized;
return $validated;
}
示例2: add
/**
* @param \Zend\Form\Form $form
* @param $data
* @return Entity\Comment|null
* @throws \Exception
*/
public function add(\Zend\Form\Form $form, $data)
{
$serviceLocator = $this->getServiceLocator();
$entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
$entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
if (!$entityType) {
throw new EntityNotFoundException();
}
$form->setData($data);
if ($form->isValid()) {
if ($entityType->getIsEnabled()) {
$data = $form->getData();
$comment = new Entity\Comment();
$comment->setEntityType($entityType);
$user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
$comment->setUser($user);
$comment->setComment($data['comment']);
$entityManager->getConnection()->beginTransaction();
try {
$hydrator = new DoctrineHydrator($entityManager);
$hydrator->hydrate($data, $comment);
$entityType->getComments()->add($comment);
$entityManager->persist($comment);
$entityManager->persist($entityType);
$entityManager->flush();
$entityManager->getConnection()->commit();
return $comment;
} catch (\Exception $e) {
$entityManager->getConnection()->rollback();
throw $e;
}
}
}
return null;
}
示例3: testExtractDataHydratorStrategy
public function testExtractDataHydratorStrategy()
{
$this->populateHydratorStrategyForm();
$hydrator = new Hydrator\ObjectProperty();
$hydrator->addStrategy('entities', new TestAsset\HydratorStrategy());
$this->form->setHydrator($hydrator);
$model = new TestAsset\HydratorStrategyEntityA();
$this->form->bind($model);
$validSet = array(
'entities' => array(
111,
333
),
);
$this->form->setData($validSet);
$this->form->isValid();
$data = $this->form->getData(Form::VALUES_AS_ARRAY);
$this->assertEquals($validSet, $data);
$entities = $model->getEntities();
$this->assertCount(2, $entities);
$this->assertEquals(111, $entities[0]->getField1());
$this->assertEquals(333, $entities[1]->getField1());
$this->assertEquals('AAA', $entities[0]->getField2());
$this->assertEquals('CCC', $entities[1]->getField2());
}
示例4: updateAction
public function updateAction()
{
if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
$this->seoForm->bind($seo);
if ($this->request->isPost()) {
$this->seoForm->setData($this->request->getPost());
if ($this->seoForm->isValid()) {
$this->seoService->update($this->seoForm->getData());
$this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
}
$view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
$view->setTerminal(true);
return $view;
}
示例5: createFromForm
/**
* createFromForm
*
* @param Form $form
* @return CdliTwoStageSignup\Model\EmailVerification
*/
public function createFromForm(Form $form)
{
$form->bind(new Model());
if (!$form->isValid()) {
return false;
}
$model = $form->getData();
$model->generateRequestKey();
$this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'form' => $form));
$this->getEmailVerificationMapper()->insert($model);
return $model;
}
示例6: persist
public function persist(Form $form)
{
$data = $form->getData();
foreach ($data['products'] as $productId => $options) {
foreach ($options as $optionId => $choiceId) {
$row = array('product_id' => $productId, 'option_id' => $optionId, 'choice_id' => $choiceId);
$this->getEntityMapper()->persist($row);
}
}
$builder = $this->newBuilderForProduct($data['product_id'], $data['parent_product_id']);
return $builder;
}
示例7: getData
/**
* @author VanCK
* @see \Zend\Form\Form::getData()
*/
public function getData($flag = FormInterface::VALUES_NORMALIZED)
{
$data = parent::getData($flag);
// populate default values
foreach ($this->getElements() as $element) {
/* @var $element \Zend\Form\Element */
if ((!count($this->data) || !array_key_exists($element->getName(), $this->data)) && $element->getValue()) {
$data[$element->getName()] = $element->getValue();
}
}
return $data;
}
示例8: getData
public function getData($flag = FormInterface::VALUES_NORMALIZED)
{
$data = parent::getData($flag);
if (false === $this->isNew()) {
foreach ($this->getOriginalFields() as $field) {
$key = 'original_' . $field;
if (array_key_exists($key, $data)) {
unset($data[$key]);
}
}
}
return parent::getData($flag);
}
示例9: saveAction
public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
{
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$createService->create($form->getData());
return $redirect->toRoute('admin-translate-words');
}
}
$view->setForm($form);
$view->setTemplate('translate/admin/word/edit');
return $view;
}
示例10: getPreparedFormData
protected function getPreparedFormData(Form $form)
{
$formData = $form->getData();
foreach ($form->getElements() as $element) {
if ($element instanceof File) {
if ($formData[$element->getName()]['size'] == 0) {
unset($formData[$element->getName()]);
} else {
$formData[$element->getName()] = $formData[$element->getName()]['tmp_name'];
}
}
}
unset($formData['save']);
return $formData;
}
示例11: write
/**
* {@inheritdoc}
*
* @param \Dms\Document\Document $document
*
* @see \Dms\Storage\StorageInterface::write()
*/
public function write(\Dms\Document\Document $document)
{
$ret = null;
$name = $document->getId();
$nameMod = substr($name, 4);
$f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
$path = $this->getBasePath() . $f;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$p = $path . $nameMod . '.dat';
if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) {
$fileInput = new FileInput(key($document->getDatas()));
$fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]);
$inputFilter = new InputFilter();
$inputFilter->add($fileInput);
$form = new Form();
$form->setInputFilter($inputFilter);
$form->setData($document->getDatas());
if ($form->isValid()) {
$form->getData();
}
} else {
$fp = fopen($p, 'w');
fwrite($fp, $document->getDatas());
$document->setWeight(strlen($document->getDatas()));
fclose($fp);
}
$conf_storage = $this->options->getStorage();
if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') {
print_r($_FILES);
$this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']);
}
$document->setSupport(Document::SUPPORT_FILE_STR);
$this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name));
$serialize = serialize($document);
$fp = fopen($path . $nameMod . '.inf', 'w');
$ret += fwrite($fp, $serialize);
fclose($fp);
$this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name));
return $ret;
}
示例12: formAction
public function formAction()
{
// Build a name element.
$name = new Element('name');
$name->setLabel('Your name');
$name->setAttributes(array('type' => 'text'));
// Build a submit button element.
$send = new Element('send');
$send->setLabel('Send');
$send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
// Build a checkbox element.
$check = new Checkbox('check');
$check->setLabel('Checkbox example');
// Build a multi-checkbox element.
$multicheck = new MultiCheckbox('multicheck');
$multicheck->setLabel('Multi checkbox example');
$multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
// Assemble the form.
$form = new Form('contact');
$form->add($name);
$form->add($check);
$form->add($multicheck);
$form->add($send);
// Get the request if any.
$request = $this->getRequest();
$data = $request->getPost();
$form->setData($data);
// Validate the form
if ($form->isValid()) {
$validatedData = $form->getData();
$success = 'Form submit was successful';
} else {
$success = 'Form submit failed';
$messages = $form->getMessages();
}
// Set the method attribute for the form
$form->setAttribute('method', 'post');
return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
}
示例13: create
/**
* @param Form $form
* @param array $data
* @return UserInterface|null
*/
public function create(Form $form, array $data)
{
$zfcUserOptions = $this->getZfcUserOptions();
$user = $form->getData();
$argv = array();
if ($this->getOptions()->getCreateUserAutoPassword()) {
$argv['password'] = $this->generatePassword();
} else {
$argv['password'] = $user->getPassword();
}
$bcrypt = new Bcrypt();
$bcrypt->setCost($zfcUserOptions->getPasswordCost());
$user->setPassword($bcrypt->create($argv['password']));
foreach ($this->getOptions()->getCreateFormElements() as $element) {
call_user_func(array($user, $this->getAccessorName($element)), $data[$element]);
}
$argv += array('user' => $user, 'form' => $form, 'data' => $data);
$this->getEventManager()->trigger(__FUNCTION__, $this, $argv);
$this->getUserMapper()->insert($user);
$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $argv);
return $user;
}
示例14: testElementInAFieldsetForSomeModel
public function testElementInAFieldsetForSomeModel()
{
$element = $this->getMoneyFieldset();
$element->init();
$fieldset = new Fieldset('hasMoneyElementFieldset');
$fieldset->add($element, ['name' => 'price']);
$fieldset->setHydrator(new ClassMethods());
$fieldset->setUseAsBaseFieldset(true);
$form = new Form();
$form->add($fieldset);
// todo: can't load this
$form->bind(new HasMoneyPropertyModel());
$data = ['hasMoneyElementFieldset' => ['price' => ['amount' => '500.25', 'currency' => 'BRL']]];
$form->setData($data);
$this->assertTrue($form->isValid());
$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue();
$currencyValue = $form->get('hasMoneyElementFieldset')->get('price')->get('currency')->getValue();
$object = $form->getData();
$this->assertSame('500.25', $amountValue);
$this->assertSame('BRL', $currencyValue);
$this->assertInstanceOf(Money::class, $object->getPrice());
$this->assertSame(50025, $object->getPrice()->getAmount());
$this->assertSame('BRL', $object->getPrice()->getCurrency()->getName());
}
示例15: processNodeForm
/**
* Verarbeitet das Formular zum Erstellen eines Nodes.
*
* @param \Zend\Form\Form $form
* @return \Zend\Http\PhpEnvironment\Response|boolean
*/
public function processNodeForm(\Zend\Form\Form $form)
{
$prg = $this->getServiceLocator()->get('controllerpluginmanager')->get('prg')->__invoke();
if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
return $prg;
} elseif (true === is_array($prg)) {
$form->setData($prg);
if (true == $form->isValid()) {
$node = $form->getData();
$this->saveNode($node);
return true;
}
}
return false;
}