2
$form = $this->form;
$form->setAttribute('action', $this->url('users', array('action' => 'login')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('uname'));
echo $this->formRow($form->get('pword'));
echo $this->formElementerrors($form->get('pword'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
양식 문제없이하지만 함께 잘 작동 로그인 폼 아래
class LoginForm extends Form
{
public function __construct($name = null)
{
parent::__construct('login');
$this->setAttribute('method', 'post');
$this->add(array('name'=>'uname','attributes'=>array('type'=>'text',),
'options'=>array('label'=>'UserName'),
));
$this->add(array('name'=>'pword','attributes'=>array('type'=>'password',),
'options'=>array('label'=>'Password'),
));
$this->add(array('name'=>'submit','attribute'=>array('type'=>'submit',
'value' => 'Go',
'class'=>'submit','id'=>'submitbutton',)
));
}
}
를 만들려면 아래 내 코드 내 로그인 페이지에 대한 코드입니다 :
- 표시 소스가 보이는 경우
submit
값을 가져 오지 않습니다.value=''
- 오류 메시지를 표시하고 싶습니다. 어디에서 그런 식으로 살아야할까요? 시도해 보았습니다.
echo $this->formElementerrors($form->getMessages('uname'));
이 문제를 해결하기위한 제안이나 아이디어가 없었습니까? 다음은
이
$form = new LoginForm();
$request = $this->getRequest();
if ($request->isPost()) {
$post = $request->getPost();
if($post->get('uname')=='')
{
$umessage='please enter username';
return $this->redirect()->toRoute('users',array('action'=>'login'));
}
$this->db =$this->getServiceLocator()->get('db');
$authAdapter = new AuthAdapter($this->db);
$authAdapter->setTableName('users')
->setIdentityColumn('uname')
->setCredentialColumn('pword');
$authAdapter->setIdentity($post->get('uname'))
->setCredential(md5($post->get('pword')));
$authService = new AuthenticationService();
$authService->setAdapter($authAdapter);
$result = $authService->authenticate();
if ($result->isValid()) {
return $this->redirect()->toRoute('users');
} else {
switch ($result->getCode()) {
case Result::FAILURE_IDENTITY_NOT_FOUND:
echo 'user name not valid dude';
break;
case Result::FAILURE_CREDENTIAL_INVALID:
echo 'password incorrect';
break;
case Result::SUCCESS:
echo 'login successfull';
break;
}
}
}
$this->layout('layout/index');
return array('form' => $form);
안녕하세요 앤드류 내 두 번째 문제는 해결되었지만 첫째 문제는 여전히 같은 ,, ... 난 이미'$ this-이> formElementerrors 시도 ($ 형상 -를>) ('UNAME'얻을); ' 그것은 오류 메시지를 표시하지 않습니다 .. : (심지어 일부 변수와 concated 시도했지만 변수 메시지가 표시되지 않습니다. – Friend
올바른 camelCase, formElementerrors => formElementErrors를 사용하여 시도 해 봤나? ZF2가 대문자를 사용하여 해결하는지 확실하지 않은가요? 보기 헬퍼에, 그것은 경우가있을 수 있습니다. 거기에 어떤 문제가있는 경우 formRow 또한 오류가 표시되어야합니다 같아요. 유효성 검사/필터 설치가 올바르게 있습니까? 게시 할 수 있습니까? – Andrew
난 입력 된 필터를 설치하지 않은 것 같아 .. 내가 확인하고 업데이 트하자 ...하지만 그 자체가 바로 처리해야 인증 플러그인을 사용하여? 제발 대체 된 질문에 의해 도대체 – Friend