Hej!
Är lite bortsnurrad på hur jag får tag på följande javascript variabel i PHP. Egentligen är det ju bara en DOM den pekar på:
var myEditor = new YAHOO.widget.Editor('news_editor', {
height: '300px',
width: '522px',
dompath: false,
animate: true
});
//The var html will now have the contents of the textarea
var html = myEditor.get('element').value;
Jag har försökt med följande i PHP utan resultat:
$DOM = new DOMDocument();
$content = $DOM->getElementById(myEditor);
//$content = $DOM->getNamedItem(myEditor);
Förslag på hur jag ska göra? Tänker jag fel när det gäller DOM?
Ska jag försöka norpa javascript variabeln istället för mitt DOM tänk? Och hur gör jag i sånna fall det?
Så här ser hela koden ut (PHP)
if (isset($_POST['add'])){
$content = $DOM->getElementById('news_editor');
//$content = $DOM->getNamedItem(myEditor);
echo $content;
if(!empty($content)){
$returned = $Manage->add($user_id, $_POST['headline'], $content);
if($returned){
$msg = "Posten är tillagd";
// header("Location: news.php?msg=".$msg);
} else {
$msg = "FEL: Något gick fel. Posten är inte tillagd.";
// header("Location: news.php?error=".$msg);
}
}
}
Och hela Yahoo Rich Editor:
<!-- ********** YUI IMAGE UPLOADER AND YAHOO RICH EDITOR ********** -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.5.0/build/assets/skins/sam/skin.css">
<script type="text/javascript" src="http://yui.yahooapis.com/2.4.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.4.0/build/element/element-beta-min.js"></script>
<script src="http://yui.yahooapis.com/2.4.0/build/container/container_core-min.js"></script>
<script src="http://yui.yahooapis.com/2.4.0/build/menu/menu-min.js"></script>
<script src="http://yui.yahooapis.com/2.4.0/build/button/button-min.js"></script>
<script src="http://yui.yahooapis.com/2.4.0/build/editor/editor-beta-min.js"></script>
<script src="http://yui.yahooapis.com/2.4.0/build/connection/connection-min.js"></script>
<script src="yui-image-uploader.js"></script>
<script type="text/javascript">
var myEditor = new YAHOO.widget.Editor('news_editor', {
height: '300px',
width: '522px',
dompath: false,
animate: true
});
// Don't forget to change the parameters of your function to point to the correct uploader script.
yuiImgUploader(myEditor, '../yui_img_uploader.php','image');
myEditor.render();
// Define various event handlers for Dialog
var handleSubmit = function() {
this.submit();
};
//Put the HTML back into the text area
myEditor.saveHTML();
//The var html will now have the contents of the textarea
var html = myEditor.get('element').value;
</script>
Och sedan koden för formuläret:
echo("
<div class=\"yui-skin-sam\">
<form action=\"news.php\" method=\"post\">
<LABEL for=\"headline\">Rubrik</LABEL>
<input type=\"text\" name=\"headline\" id=\"headline\">
<textarea name=\"news_editor\" id=\"news_editor\" cols=\"50\" rows=\"10\">
</textarea>
<input type=\"submit\" class=\"submit\" name=\"add\" value=\"Spara\" />
</form>
</div>
");