0

Ok, i have some data that is being populated via a php query to a database. I am getting comments that a user enters. I am displaying the returned data in a variable as shown below. If a comment does not exist then it would display an "add comment" link. The comment is just displayed as text at first. If a comment exists then it would display the comment along with an "edit" comment" link.

This is the functionality i am looking to have: 1) when you click on "add comment" an input field would be displayed to the left of the "add comment" link and that link would then turn in to two links that read "save" and "cancel". I know how to do the save link but i would like to know how to make the "cancel" link revert the area back to just having the "add comment" link. 2) when you click on "edit comment" then i would like the same functionality with an input field and the "save" and "cancel" links; however, i would like the input field to be pre-populated with the comments text that is being pulled via the comments variable. I'm thinking maybe this can be done with some css display toggling none and block/inline. Not sure exactly though. Any help is greatly appreciated!

PHP Code:

if(!$comments){
    echo "<span style='font-size:12px;'>[<a href='#'>Add a Comment</a>]</span>";
}else{
    echo "<span style='font-size:12px;'>NOTES: " . $comments . " [<a href='#'>Edit Comment</a>]</span>";
}

One final question: how should i handle if the comments have special characters or quotes? Actually i guess i'll need to worry about those before teh variable is created, correct? How do i do that? Thanks so much!

UPDATE: I appreciate the help on handling special characters, but i really need the first two questions answered more. Thanks for any more help anyone can provide me!

4 Answers 4

3

answer to 1st and 2nd question : you can play with javascript or jquery....for eg

make 2 divs

<div id="addcommentBox" style='font-size:12px;'>[<a onclick="$('#addcommentBox').hide();$('#savecommentbox').show();">Add a Comment</a>]</div>
<div id="savecommentbox"><input type="text"/><a href="#">Save</a><a onclick="$('#addcommentBox').show();$('#savecommentbox').hide();">Cancel</a></div>

give css property to #savecommentbox as display:none;

although there are many ways this is the simple one...for edit also you can follow the same code.just give the input value as $comments

Sign up to request clarification or add additional context in comments.

Comments

1

You have to pass the variable from htmlspecialchars() before echoing them.

echo "<span style='font-size:12px;'>
        NOTES: " . htmlspecialchars($comments) . " 
        [<a href='#'>Edit Comment</a>]
      </span>";

<textarea name="comment"><?php echo htmlspecialchars($comments);?></textarea>

Comments

0

you can use htmlentities

Comments

0
  1. one answer as many have given is htmlspecialchars().

  2. when you click on the add comment link . show the text area. when you click on the cancel, do a hide of the text area and show the add comment link again. i feel if u use jquery u can use show / hide functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.