Code Igniter表单提交返回空页面

时间:2016-01-24 04:01:38

标签: php forms

我把这个代码丢弃在我身上。我对Code Ignitor一无所知,对php有点了解。我有一个返回所选值的表单。但是,当我单击提交按钮时,它会返回到正确的页面,但根本没有代码。我无法弄清楚问题出在哪里。声明似乎没有通过设置用户ID进入数据库,所以我不认为它已经走得那么远。我该怎么办?

表格:

<form method="post" action="/sp/makeClaim">
  <div class="text-center" style="padding-bottom: 20px;">
    <select name="spId">
      <option value="-1"<?php $this->printSelected($spId, -1);?>>-- Choose a Service Provider --</option>
      <?php
      foreach ($spData as $id => $name)
      {
        ?>
        <option value="<?php echo $id; ?>"<?php $this->printSelected($spId, $id);?>><?php print($name); ?></option>
      <?php
      }
      ?>
    </select>
  </div>

  <div class="text-center">
    <input type="submit" class="btn btn-default sp" value="Make Claim from List Above" /><br />
    or<br />
    <a href="/sp/create/" class="btn btn-default sp">Add Your Service Provider Information</a>
  </div>
</form>

控制器代码:

public function makeClaim()
{
  $formDefaults = array(
    'spId' => -1
  );

  if ($this->input->post())
  {
    foreach ($formDefaults as $key => $defaultValue)
    {
      $$key = trim($this->input->post($key));

      if ($spId == -1)
      {
        $this->addError('You must choose the service provider you wish to claim.');
      }
    }

    $sp = $this->getEm()->getRepository('Entities\ServiceProvider')->findOneBy(array('id' => $spId));
    if (is_null($sp))
    {
      $this->addError('A service provider with that ID could not be found.');
    }

    if (count($this->getErrors()) == 0)
    {
      $claim = new \Entities\Claim();
      $claim->setUser($this->getUser());
      $claim->setSP($sp);
      $claim->setStatus('New');
      $claim->setLastUpdated(new DateTime(date('Y-m-d H:i:s')));
      $claim->setLastUpdatedBy($this->getUser()->getRealName() . ' (' . $this->getUser()->getId() . ')');

      $this->em->persist($claim);
      $this->em->flush();
      $this->_redirect(true, 'Your claim on that service provider account has been submitted for review. We will contact you with a status update after we review your request.', '/sp/makeClaim/');
    }

0 个答案:

没有答案