Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony表单-不';不要提交也不要显示错误_Php_Symfony1_Symfony 1.4 - Fatal编程技术网

Php Symfony表单-不';不要提交也不要显示错误

Php Symfony表单-不';不要提交也不要显示错误,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我基于Symfony教程构建了以下表单 UsersForm.class.php: class UsersForm extends BaseUsersForm { public function configure() { $this->useFields(array('username', 'password', 'email', 'tara', 'gen')); $this->widgetSchema['passwor

我基于Symfony教程构建了以下表单

UsersForm.class.php:

class UsersForm extends BaseUsersForm
    {
      public function configure()
      {
        $this->useFields(array('username', 'password', 'email', 'tara', 'gen'));
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['email'] = new sfWidgetFormInputText();
        $this->validatorSchema['email'] = new sfValidatorAnd(array(
            $this->validatorSchema['email'],
            new sfValidatorEmail(),
        ));
        $this->widgetSchema['tara'] = new sfWidgetFormChoice(array(
            'choices'  => Doctrine_Core::getTable('Users')->getTara(),
                'expanded' => false,
            'multiple' => false,
        ));
        $this->validatorSchema['tara'] = new sfValidatorChoice(array(
            'choices' => array_keys(Doctrine_Core::getTable('Users')->getTara()),
        ));
        $this->widgetSchema['gen']= new sfWidgetFormChoice(array(
            'choices'  => Doctrine_Core::getTable('Users')->getGen(),
            'expanded' => false,
            'multiple' => false,
        ));
        $this->validatorSchema['gen'] = new sfValidatorChoice(array(
            'choices' => array_keys(Doctrine_Core::getTable('Users')->getGen()),
        ));
        $this->widgetSchema->setLabels(array(
            'username'    => 'Utilizator',
            'password'    => 'Parolă',
            'email'       => 'Adresă de email',
            'tara'        => 'Ţara',
        'gen'         => 'Gen',
        ));
        $this->setValidators(array(
            'username' => new sfValidatorString(array('min_length' => 4),
                    array('required' => 'Câmp obligatoriu',
                    'min_length' => 'Minim %min_length% caractere.',)),
            'password' => new sfValidatorString(array('min_length' => 4),
                    array('required' => 'Câmp obligatoriu',
                        'min_length' => 'Minim %min_length% caractere.',)),
        ));
        $this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array(
            //'public_key' => sfConfig::get('app_recaptcha_public_key')
            'public_key' => '/*...*/'
        ));

        $this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array(
            //'private_key' => sfConfig::get('app_recaptcha_private_key')
        'private_key' => '/*...*/'
        ));
      }
    }
public function executeCreate(sfWebRequest $request)
{
    $this->setLayout(false);
    $this->form = new UsersForm();
    $this->processForm($request, $this->form);
}
public function executeRegister(sfWebRequest $request)
{
    $this->setLayout('register');
    $this->form = new UsersForm();
    $this->setTemplate('register');
}
protected function processForm(sfWebRequest $request, sfForm $form)
{
    $captcha = array(
        'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
        'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
    );
    $form->bind(array_merge(
        $request->getParameter($form->getName()),
        array('captcha' => $captcha)));

    if ($form->isValid())
    {
        $user = $form->save();

        $this->redirect('/');
    }
}
Actions.class.php:

class UsersForm extends BaseUsersForm
    {
      public function configure()
      {
        $this->useFields(array('username', 'password', 'email', 'tara', 'gen'));
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['email'] = new sfWidgetFormInputText();
        $this->validatorSchema['email'] = new sfValidatorAnd(array(
            $this->validatorSchema['email'],
            new sfValidatorEmail(),
        ));
        $this->widgetSchema['tara'] = new sfWidgetFormChoice(array(
            'choices'  => Doctrine_Core::getTable('Users')->getTara(),
                'expanded' => false,
            'multiple' => false,
        ));
        $this->validatorSchema['tara'] = new sfValidatorChoice(array(
            'choices' => array_keys(Doctrine_Core::getTable('Users')->getTara()),
        ));
        $this->widgetSchema['gen']= new sfWidgetFormChoice(array(
            'choices'  => Doctrine_Core::getTable('Users')->getGen(),
            'expanded' => false,
            'multiple' => false,
        ));
        $this->validatorSchema['gen'] = new sfValidatorChoice(array(
            'choices' => array_keys(Doctrine_Core::getTable('Users')->getGen()),
        ));
        $this->widgetSchema->setLabels(array(
            'username'    => 'Utilizator',
            'password'    => 'Parolă',
            'email'       => 'Adresă de email',
            'tara'        => 'Ţara',
        'gen'         => 'Gen',
        ));
        $this->setValidators(array(
            'username' => new sfValidatorString(array('min_length' => 4),
                    array('required' => 'Câmp obligatoriu',
                    'min_length' => 'Minim %min_length% caractere.',)),
            'password' => new sfValidatorString(array('min_length' => 4),
                    array('required' => 'Câmp obligatoriu',
                        'min_length' => 'Minim %min_length% caractere.',)),
        ));
        $this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array(
            //'public_key' => sfConfig::get('app_recaptcha_public_key')
            'public_key' => '/*...*/'
        ));

        $this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array(
            //'private_key' => sfConfig::get('app_recaptcha_private_key')
        'private_key' => '/*...*/'
        ));
      }
    }
public function executeCreate(sfWebRequest $request)
{
    $this->setLayout(false);
    $this->form = new UsersForm();
    $this->processForm($request, $this->form);
}
public function executeRegister(sfWebRequest $request)
{
    $this->setLayout('register');
    $this->form = new UsersForm();
    $this->setTemplate('register');
}
protected function processForm(sfWebRequest $request, sfForm $form)
{
    $captcha = array(
        'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
        'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
    );
    $form->bind(array_merge(
        $request->getParameter($form->getName()),
        array('captcha' => $captcha)));

    if ($form->isValid())
    {
        $user = $form->save();

        $this->redirect('/');
    }
}
Routing.yml:

register_create:
  url:     /register.:sf_format
  class:   sfDoctrineRoute
  options: { model: Users, type: object }
  param:   { module: home, action: register, sf_format: html }
  requirements: { sf_method: post }

register_new:
  url:     /register.:sf_format
  class:   sfDoctrineRoute
  options: { model: Users, type: object }
  param:   { module: home, action: register, sf_format: html }
虽然不会显示错误,也不会更新数据库。这更像是我提交表单时的刷新

我是Symfony的新手,我自己找不到错误

乐:

_form.php:

<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<?php echo form_tag_for($form, '@register') ?>
  <table id="register_form">
    <tfoot>
      <tr>
        <td colspan="2">
          <input type="submit" value="Înregistrează-te" />
        </td>
      </tr>
    </tfoot>
    <tbody>
        <?php echo $form ?>
    </tbody>
  </table>
</form>

registerSuccess.php:

<?php include_partial('form', array('form' => $form)) ?>

表单可能会抛出一个无法呈现的错误。尝试在
BaseForm
类(lib/form/BaseForm.class.php)中包含此调试代码,并查看在视图中调用它时得到的输出

public function debug()
{
  if (sfConfig::get('sf_environment') != 'dev')
  {
    return;
  }
  foreach($this->getErrorSchema()->getErrors() as $key => $error)
  {
    echo '<p>' . $key . ': ' . $error . '</p>';
  }
}
公共函数调试()
{
if(sfConfig::get('sf_环境')!='dev')
{
返回;
}
foreach($this->getErrorSchema()->getErrors()作为$key=>$error)
{
回显“”.$key.:“.$error.”

”; } }
添加后

$this->widgetSchema->setNameFormat('register[%s]');
到UsersForm.class.php


到actions.class.php;我设法让表单显示错误。

你也能显示HTML部分吗?我显示了。我包括了代码,刷新了缓存,在开发模式下运行,但是没有显示任何错误。