Skip to content
Snippets Groups Projects
Commit a163e187 authored by goujonpa's avatar goujonpa
Browse files

phonefield

parent eb13ef65
No related branches found
No related tags found
No related merge requests found
......@@ -13,9 +13,10 @@ class BoolField extends Field
public function validate()
{
if (isset($_POST[$this->name]))
$this->value = $_POST[$this->name];
else
$this->value = NULL;
if ($_POST[$this->name] == 'on')
$this->value = true;
else
$this->value = false;
return true;
}
}
......
......@@ -11,9 +11,9 @@ class Field {
public function html() {
// Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
return '<div class="form-group">
<label for="form'.$this->name.'">'.ucfirst($this->name).'</label>
<input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" >
</div>';
<label for="form'.$this->name.'">'.ucfirst($this->name).'</label>
<input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" >
</div>';
}
/*
......@@ -21,8 +21,12 @@ class Field {
and return false, if data is not valid !
*/
public function validate() {
$this->value = $_POST[$this->name];
return true;
if (isset($_POST[$this->name]))
{
$this->value = $_POST[$this->name];
return true;
}
return false;
}
}
<?
class PhoneField extends Field
{
public function html() {
$html = '<div class = "checkbox">
<label for = "form'.$this->name.'">
<input type = "tel" name = "'.$this->name.'" value ="'.$this->value.'"> '.ucfirst($this->name).'
</label>
</div>';
return $html;
}
public function validate()
{
if (isset($_POST[$this->name]))
{
$_POST[$this->name] = htmlspecialchars($_POST[$this->name]);
if (preg_match("#^0[1-68]([-. ]?[0-9]{2}){4}$#", $_POST[$this->name]))
{
$this->value = $_POST[$this->name];
return true;
}
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment