PHP - Porqué me devuelve paréntesis en vez de mostrar correctamente el formulario

 
Vista:

Porqué me devuelve paréntesis en vez de mostrar correctamente el formulario

Publicado por nacheret (1 intervención) el 22/02/2018 12:52:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
 
	class Formulario{
 
		//Atributos
		private $nombre; private $metodo; private $accion; private $etiqueta;
		private $elementos; //elementos del formulario: TEXT, SELECT, SUBMIT...
		//Funciones
		function __construct($pNombre, $pMetodo, $pAccion, $pElementos, $pEtiqueta){
			$this->nombre = $pNombre; $this->metodo = $pMetodo; $this->accion = $pAccion;
			$this->etiqueta = $pEtiqueta; $this->elementos = $pElementos;
		}
		function toString(){
			$string = "$this->etiqueta";
			$string .= "<form name='$this->nombre' method='$this->metodo' action='$this->accion'>";
			foreach ($this->elementos as $elemento) {
				$string .= "$elemento->toString()";
			}
			$string .= "</form>";
			return $string;
		}
	}
	//Incorporamos las clases anteriores
	require_once('Clases.php');
	//Creamos los Objetos
	//Campos de Texto
	$texto1 = new Input();
	$texto1->setTipo('text');
	$texto1->setNombre("Texto1");
	$texto1->setEtiqueta('Escribe tu nombre: ');
	$texto1->setTexto('Nombre...');
	//Select
	$elementosSelect = array('Uno','Dos','Tres','Cuatro');
	$select = new Select($elementosSelect);
	//RadioButton
	$elementos = array('Uno','Dos','Tres','Cuatro');
	$radio = new Radio ($elementos);
	//Submit
	$submit = new Input();
	$submit->setNombre("Boton1");
	$submit->setEtiqueta("<hr>");
	$submit->setTipo('submit');
	$submit->setTexto("Enviar");
	//Formulario
	$elementosFormulario = array($texto1, $select, $radio, $submit);
	$formu = new Formulario("Form1", "POST", "", $elementosFormulario, "<b>Formulario: </b><hr>");
	echo $formu->toString();
 
?>

vemos el otro archivo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
 
	//Clase CheckBox
	class Checkbox{
		//Atributos
		private $elementos = array(); private $nombre; private $etiqueta;
		//Funciones
		function __construct($pElementos, $pNombre='miCheckbox', $pEtiqueta='Elige una opción'){
			$this->elementos = $pElementos;
			$this->nombre = $pNombre;
			$this->etiqueta = $pEtiqueta;
		}
 
		function setOpcion ($pOpcion) {$this->opcion = $pOpcion;}
		function toString(){ //genera una cadena con el código html de la select
			$string = "<hr>$this->etiqueta<br>";
			foreach ($this->elementos as $clave => $valor) {
				$string .= "<input type='checkbox' name='$this->nombre'";
				$string .= " value='$valor' > ";
				$string .= " $valor ";
				$string .= "</input>";
			}
			$string .= "<hr>";
			return $string;
		}
	}
 
	//Clase RadioButton
	class Radio{
		//Atributos
		private $elementos = array(); private $nombre; private $etiqueta;
		//Funciones
		function __construct($pElementos, $pNombre='miRadio', $pEtiqueta='Elige una opción: '){
			$this->elementos = $pElementos;
			$this->nombre = $pNombre;
			$this->etiqueta = $pEtiqueta;
		}
 
		function toString(){ //genera una cadena con el código html de la select
			$string = "<hr>$this->etiqueta<br>";
			foreach ($this->elementos as $clave => $valor) {
				$string .= "<input type='radio' name='$this->nombre'";
				$string .= " value='$valor' > ";
				$string .= " $valor ";
				$string .= "</input>";
			}
			$string .= "<hr>";
			return $string;
		}
	}
 
	//Clase Input
	class Input{
		private $tipo; private $nombre; private $etiqueta; private $texto;
		function setNombre ($pNombre) {$this->nombre = $pNombre;}
		function setEtiqueta ($pEtiqueta) {$this->etiqueta = $pEtiqueta;}
		function setTexto ($pTexto) {$this->texto = $pTexto;}
		function setTipo ($pTipo) {$this->tipo = $pTipo;}
		function toString(){ //Genera una cadena con el código html del radiobutton
			$string = $this->etiqueta;
			$string .= "<input type='$this->tipo' name='$this->nombre' value='$this->texto'>";
				return $string;
		}
	}
 
	//Clase Select
	class Select{
		//Atributos
		private $elementos = array(); private $nombre; private $etiqueta;
		//Funciones
		function __construct($pElementos, $pNombre='miSelect', $pEtiqueta='Elige una opción: '){
			$this->elementos = $pElementos;
			$this->nombre = $pNombre;
			$this->etiqueta = $pEtiqueta;
		}
 
		function toString(){ //genera una cadena con el código html de la select
			$string = "$this->etiqueta <br> <select name='".$this->nombre ."'>";
			foreach ($this->elementos as $clave => $valor) {
				$string .= "<option value = '$clave' > $valor";
			}
			$string .= "</select>";
			return $string;
		}
	}
 
?>



¿Porqué me devuelve paréntesis en vez de mostrar correctamente el formulario?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder