Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Dwa obowiązkowe checkboxy
phpkm
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.09.2010

Ostrzeżenie: (0%)
-----


Witam

Mam obecnie na stronie obowiązkowy jeden checkbox, chciałbym dodać drugi, tak aby możliwe było przejście do kolejnej strony jedynie po zaznaczeniu obydwu.

Dodałem na stronie drugi chceckbox i teraz wygląda to tak:
  1. <input id="tac" type="checkbox" name="tac" value="1" /> akcept 1
  2. <input id="tac2" type="checkbox" name="tac2" value="1" /> akcept 2


W kontrolerze wygląda to tak:
  1. <?php
  2. class CartController extends Zend_Controller_Action
  3. {
  4.  
  5. public function regulationsAction() {
  6. if (!$this->_request->isPost())
  7. {
  8. return $this->_helper->_redirector->gotoRoute(array(), 'cart');
  9. }
  10.  
  11. $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
  12. $cart = Zend_Registry::get('cart');
  13.  
  14. if($this->_getParam('tac') == 1) {
  15. $cart->tac = true;
  16. return $this->_helper->_redirector->gotoRoute(array(), 'delivery');
  17. }
  18. elseif($this->_getParam('tac') == 0) {
  19. $cart->tac = false;
  20. $this->_flashMessenger->addMessage(array(0, 'Zaakceptuj accept 1.'));
  21. return $this->_helper->_redirector->gotoRoute(array(), 'cart');
  22. }
  23. }
  24. ...


Wie ktoś co należy zmienić i gdzie ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
phpkm
post
Post #2





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 12.09.2010

Ostrzeżenie: (0%)
-----


Najcześciej dzieje się tak, że wystarczy zaznaczyć 1 z 2 obowiązkowych chceckboxow i można przejść dalej. To niestety nie może tak działać. Czy poniżej dobrze kombinuje (pogrubiona czcionka) ?


public function regulationsAction() {
if (!$this->_request->isPost())
{
return $this->_helper->_redirector->gotoRoute(array(), 'cart');
}

$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
$cart = Zend_Registry::get('cart');

if($this->_getParam('tac') == 1) {
$cart->tac = true
&&
($this->_getParam('tac2') == 1) {
$cart->tac2 = true;

return $this->_helper->_redirector->gotoRoute(array(), 'delivery');
}
elseif($this->_getParam('tac') == 0) {
$cart->tac = false
&&
($this->_getParam('tac2') == 0) {
$cart->tac2 = false;

$this->_flashMessenger->addMessage(array(0, 'Zaakceptuj accept 1,2.'));
return $this->_helper->_redirector->gotoRoute(array(), 'cart');
}
}
...
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.09.2025 - 15:08