1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: * @package Nette\Forms
11: */
12:
13:
14:
15: /**
16: * Submittable image button form control.
17: *
18: * @author David Grudl
19: * @package Nette\Forms
20: */
21: class NImageButton extends NSubmitButton
22: {
23:
24: /**
25: * @param string URI of the image
26: * @param string alternate text for the image
27: */
28: public function __construct($src = NULL, $alt = NULL)
29: {
30: parent::__construct();
31: $this->control->type = 'image';
32: $this->control->src = $src;
33: $this->control->alt = $alt;
34: }
35:
36:
37:
38: /**
39: * Returns name of control within a Form & INamingContainer scope.
40: * @return string
41: */
42: public function getHtmlName()
43: {
44: $name = parent::getHtmlName();
45: return strpos($name, '[') === FALSE ? $name : $name . '[]';
46: }
47:
48:
49:
50: /**
51: * Loads HTTP data.
52: * @return void
53: */
54: public function loadHttpData()
55: {
56: $path = $this->getHtmlName(); // img_x or img['x']
57: $path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_'));
58: $this->setValue(NArrayTools::get($this->getForm()->getHttpData(), $path) !== NULL);
59: }
60:
61: }
62: