I have some problem with posting data in codeigniter. I want to make an editor for .php files and when i want to post a string like this
<?php echo $my_var; ?><p>sample text</p>
the obtained result in
$_POST['element_name']
is
<!--<?php echo $my_var; ?>--><p>sample text</p>
Why happen this? How i can obtain the original text?
Here is part of my code
HTML
<form role="form" accept-charset="utf-8" method="post" action="">
<textarea id="editor_original"><?php echo $editor_original;?></textarea>
<textarea name="editor" id="editor"></textarea>
<input type="submit" value="Save" />
</form>
JAVASCRIPT
var editor = CodeMirror.fromTextArea(document.getElementById('editor_original'), {
lineNumbers: true,
extraKeys: {"Ctrl-Space": "autocomplete"},
keyMap: "sublime",
autoCloseBrackets: true,
matchBrackets: true,
mode: "application/x-httpd-php",
showCursorWhenSelecting: true,
theme: "monokai",
onBlur: function () {
editor.save();
}
});
$("#editor").val(editor.getValue());
PHP
$data = $this->page_m->array_from_post(array('editor'));
echo $data; // here output is <!--<?php echo $my_var; ?>--><p>sample text</p>
public function array_from_post($fields)
{
$data = array();
foreach($fields as $field)
{
$data[$field] = $this->input->post($field);
}
return $data;
}