So I have a method that creates a text element based on an array of attributes you pass in, it all works except for the value attribute, eseentially the issue is as follows:
if some value, be it a function, text or what have you is “echo’d” out, then the value is displayed out side the box, how ever if the value is returned then we get the value inside the tags.
code
function textarea(array $attributes){
if(isset($attributes['name'])){
$this->name = 'name="'.$attributes['name'].'"';
}
if(isset($attributes['id'])){
$this->id = 'id="'.$attributes['id'].'"';
}
if(isset($attributes['class'])){
$this->class = 'class="'.$attributes['class'].'"';
}else{
$this->class = 'class="aisisTextElement"';
}
if(isset($attributes['rows'])){
$this->rows = 'rows="'.$attributes['rows'].'"';
}
if(isset($attributes['cols'])){
$this->cols = 'cols="'.$attributes['cols'].'"';
}
if(isset($attributes['value'])){
$this->value = $attributes['value'];
}
if(isset($attributes['style'])){
$this->style = 'style="'.$attributes['style'].'"';
}
$build_aisis_element = '<textarea '
.$this->id
.$this->class
.$this->name
.$this->rows
.$this->cols
.$this->style
.'>'.$this->value . '</textarea>';
echo $build_aisis_element;
}
For example:
if this function is passed in as the value:
function echo_me(){
echo "hello"
}
My html will look like:
hello
<textarea></textarea>
how ever
function return_me(){
return "hello"
}
My html is:
<textarea>hello</textarea>
Why is this?
The echo command outputs the string to the document, not to the calling function.
Return takes the string and passes it back to the calling function to do with it what it will.