Reputation: 673
little help here please....I was writing a php script for a message system. comments are displayed in php with the use of $comments through a function. I was trying to use a light box in javascript, so that user will have the option to delete each comment. How can I combine the following php script with the javascript code:
<?php
$comments .= " <font size='3'> ?>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">**Delete**</a>
<div id="light" class="white_content">
<form action="<?php=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit_1" value="Delete Photo" >
</form>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><button> Cancel </button></a></div>
<div id="fade" class="black_overlay"></div>
<?php $comments .= "</font>"; ?>
Upvotes: 0
Views: 129
Reputation: 340
<?php
$comments .= <<<EOD
<font size='3'>
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">**Delete**</a>
<div id="light" class="white_content">
<form action="$_SERVER[PHP_SELF]" method="post">
<input type="submit" name="submit_1" value="Delete Photo" >
</form>
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><button> Cancel </button></a>
</div>
<div id="fade" class="black_overlay"></div>
</font>
EOD;
?>
Something like that should work. Remember that the "EOD;" needs to be on it's own, at the very beginning of a line.
See also http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
You're trying to use the "?> html... " construct incorrectly. It doesn't "return" the string, it prints it out directly - it will get sent to the browser whenever the parser passes over it, rather than being added to $comments
Upvotes: 1
Reputation: 16828
There are two syntax errors:
1, You're missing the closing double quotes from line 3:
$comments .= " <font size='3'> "
2, <?php=
is invalid and should be used as:
<?php echo
or <?=
(shorthand echo statements must be enabled to use <?=
)
here: <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
If you're looking to make your entire block of code 1 string then i would recommend using a heredoc statement like:
<?php
$comments .= <<<EOD
<font size="3">
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">**Delete**</a>
<div id="light" class="white_content">
<form action="{$_SERVER['PHP_SELF']}" method="post">
<input type="submit" name="submit_1" value="Delete Photo" >
</form>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><button> Cancel </button></a>
</div>
<div id="fade" class="black_overlay"></div>
</font>
EOD;
?>
Upvotes: 1