Reputation: 69
I want to display images while editing the information of the user. I just bind the form with fetched data and displaying all data with single array i.e form. Also is there any way to get https 500 error? If yes then please show me some code so that I can display the error and check why it is giving HTTPS 500 error.
controller
public function editAction() {
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('business', array(
'action' => 'add'
));
}
try {
$business = $this->getBusinessTable()->getBusiness($id);
} catch (\Exception $ex) {
return $this->redirect()->toRoute('business', array(
'action' => 'index'
));
}
$form = new BusinessForm();
$form->bind($business); /// values to the form
$form->get('submit')->setAttribute('value', 'Update business info');
$request = $this->getRequest();
if ($request->isPost()) {
// $form->setData($request->getPost());
$post = array_merge_recursive(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$this->getBusinessTable()->saveBusiness($business);
// Redirect to list of Student
return $this->redirect()->toRoute('business');
}
}
return array(
'id' => $id,
'form' => $form,
);
}
view file edit.phtml
<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url(NULL, array('controller' => 'TaskForce', 'action' => 'add')));
$form->setAttribute('method', 'post');
//echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
?>
<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">Add Bsuiness</div>
<div class="panel-body">
<?php echo $this->form()->openTag($form); ?>
<fieldset>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('fname')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('lname')); ?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('phone')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('email')); ?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('address')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('company')); ?>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<?php echo $this->formElement($form->get('images')); ?>
</div>
<?php print_r($form->get('images')); ?>
<?php $img_ar=explode(',', $form->images); ?>
<ul>
<?php foreach ($img_ar as $myimg) { ?>
<li>
<img src="<?php echo $this->basePath(); ?>/images/<?php echo $myimg; ?>" style="width: 60px;height: 60px;"></li>
<?php } ?>
</div>
<div class="col-md-12">
<?php echo $this->formElement($form->get('submit')); ?>
</div>
</fieldset>
<?php echo $this->form()->closeTag();
?>
</div>
</div>
</div><!-- /.col-->
</div><!-- /.row -->
Upvotes: 1
Views: 41