Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function __sleep()
/**
* Define an attribute
*/
public function setAttribute($name, $value)
public function setAttribute($name, $value, $quote = '"')
{
$this->attributes[$name] = $value;
$this->attributes[$name] = ['value' => $value, 'quote' => $quote];
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public function unsetAttribute($name)
/**
* Function called by the dispatcher
*/
public function push($name, $value = null)
public function push($name, $value = null, $quote = '"')
{
switch ($name) {
case 'name':
Expand Down Expand Up @@ -162,9 +162,9 @@ public function push($name, $value = null)
default:
if (preg_match('#^([a-z0-9_-]+)$#mUsi', $name)) {
if (null !== $value) {
$this->setAttribute($name, $value);
$this->setAttribute($name, $value, $quote);
} else {
$this->setAttribute($name, $name);
$this->setAttribute($name, $name, $quote);
}
}
}
Expand Down Expand Up @@ -314,7 +314,8 @@ public function getHtml()
$html = '<input ';

foreach ($this->attributes as $name => $value) {
$html.= $name.'="'.$value.'" ';
$quote = $value['quote'];
$html.= $name."={$quote}{$value['value']}{$quote} ";
}

if ($this->required) {
Expand All @@ -325,7 +326,8 @@ public function getHtml()
$html.= 'name="'.$this->getName().'" ';

if (($value = $this->getValue()) !== null && gettype($value) != 'object') {
$html.= 'value="'.htmlspecialchars($value).'" ';
$quote = $value['quote'];
$html.= "value={$quote}".htmlspecialchars($value)."{$quote}";
}

$html.= '/>';
Expand Down
3 changes: 2 additions & 1 deletion Fields/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function getOptionHtml($selected)
{
$html = '<option ';
foreach ($this->attributes as $name => $value) {
$html.= $name.'="'.$value.'" ';
$quote = $value['quote'];
$html.= $name."={$quote}{$value['value']}{$quote} ";
}
if ($selected) {
$html.='selected="selected" ';
Expand Down
7 changes: 4 additions & 3 deletions Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Select extends Field
*/
protected $options = array();

public function push($name, $value = null)
public function push($name, $value = null, $quote = '"')
{
if ($name == 'multiple') {
$this->multiple = true;
Expand All @@ -33,7 +33,7 @@ public function push($name, $value = null)
$this->allowAdd = true;
}

parent::push($name, $value);
parent::push($name, $value, $quote);
}

public function __sleep()
Expand Down Expand Up @@ -130,7 +130,8 @@ public function getHtml()

$html = '<select name="'.$this->getName().$arr.'" ';
foreach ($this->attributes as $name => $value) {
$html.= $name.'="'.$value.'" ';
$quote = $value['quote'];
$html .= $name."={$quote}{$value['value']}{$quote} ";
}
$html.= ">\n";

Expand Down
9 changes: 6 additions & 3 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function parse($content)
}

$this->push(new PostIndicator($name));
}
}

$this->push('</form>');
break;
Expand Down Expand Up @@ -310,12 +310,15 @@ public function doParseTag(&$name, &$data)
$value = null;

if (isset($match[5])) {
// Single quotes are being used
$quote = "'";
$value = trim($match[5]);
} else if (isset($match[4])) {
// Double quotes are being used
$quote = '"';
$value = trim($match[4]);
}

$field->push($key, $value ? html_entity_decode($value) : $value);
$field->push($key, $value ? html_entity_decode($value) : $value, $quote);
}, $data);

return $field;
Expand Down