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!
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"/>Save<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
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>
you can use htmlentities
one answer as many have given is htmlspecialchars().
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.
Related
I know that it's kind of wrong to ask a question that's almost been answered in the past, but even though I'm trying to use this solution, it doesn't work.
Basically, I have a php table with a search link created in a HTML button from the strings inside the table.
Let's say that this string is creating a search in the website called Discogs and that the information I'm searching through a created link is the word "Beatles".
www.discogs.com/search/?q=Beatles
You notice the ?q=
Everytime I click on the link through a php code which looks like this, the opened link brings me to www.discogs.com/search/? WITHOUT THE REST OF STRINGS (in that case, the word Beatles)
I tried to rawurlencode the ? to have it as a %3F.
Here is what my code looks like
$discogslink = 'http://www.discogs.com/search/'.rawurlencode('?').'q='.'Beatles' ;
$form = "<form action='$discogslink' >";
$form .= "<input type='submit' value='Discogs'>";
$form .= "</form>";
echo '<td class="'.$lps->type.'">'.$form.' </td>';
The link that I would like to open is
http://www.discogs.com/search/?q=Beatles
The link that opens is :
http://www.discogs.com/search/? (nothing after the '?'...)
Do you have any idea why it does that?
BONUS QUESTION : How can I make the button open in a new tab instead of the same one?
The reason for this is the default behaviour of HTML forms. They send data as a GET request, just like links do. So in your case the content of the form (which is empty) overwrites your q-parameter because the form content wins over the parameters specified in the action link.
The solution is to add a hidden field:
<input type="hidden" name="q" value="Beatles"></input>
And concerning the new window:
<form target="_blank" ...
Please can I get some help with this - I have this part of code:
echo '<li><span>'.mg_wpml_string($type, $copt).':</span> '.$val.'</li>';
How to make this part
.$val.
clickable, so In fact how to put this part in a href so that users can click on this?
This is ordinary text ling but all values are entered as http addresses but I can not click on them.
Thank you
Just put the HTML-code for a link (a href) in there...
echo '<li><span>'.mg_wpml_string($type, $copt).':</span> '.$val.'</li>';
Perhaps?
[...snip...]:</span>' . $val . '</li>';
In a php project I need to add items to database, list them & allow the user to edit & update items using a single page.
This is my code to edit item link in HTML table
echo ' Edit ';
When a user click on the above link I need to hide Add button and display two new buttons to Update & Cancel the edit + display selected item name in a Text box to Edit.
To hide and display buttons I'm using jQuery and to display the item name i need to use PHP.
Here when i put PHP code and reload the page with $_SERVER['PHP_SELF'] (as in above code), hiding & displying of buttons is lost after the page load. (If I remove the _SERVER['PHP_SELF'] code from link it hides and display buttons as expected (but no php code run))
How can I retain the page update by Javascript and run the PHP code?
I'm new to PHP am I missing something in my code?
$_SERVER['PHP_SELF'] is only a refrence to the php document itself, it doesnt contain any key/value pairs. try using:
echo '<a href=" '.$_SERVER['PHP_SELF'].'?'. $_SERVER['QUERY_STRING'].
'&name=edit&id=' .$rowCountry->CountryId .
' " id="edit" onClick="MyFunction()"> Edit </a>';
edit:
i may have misunderstood the question. you may need something like this:
<?php
if(!empty($_GET[edit])){
//echo code that u want to show AFTER they click the edit link
}else{
//echo the code to show if they have NOT clicked the edit link
}
?>
This is the whole source code, i would like to modify it to add a new column to show the
Client Mobile
Client Office Telephone
Client E-mail
in an another popup php pages.
What i have attempted is to add a form and a submit button to create a new column , when i press that submit button, the mobile, office,email information will post to another php page to print out. however, since there is a another form exist already, when i add a form ,the function in the following form will not work. (Don't worries , i will indicate where the problems happen.)
it is a complicated question. Thanks in advance
The source code is here:
https://docs.google.com/leaf?id=0B196kQ-9lu50OTI1NDZkMjktNzAzNi00MmM0LWIzMjgtNTQxMTIyZmYyM2I1&hl=en_US
the problem is at line 99
p.s. I just found out the form method can not get my job done, since it can not create a popup window for the information at the same time.
Looks like at line 126 there is an extra </form> tag. Delete it...that might help.
EDIT:
Ok. So it needs to look something like this:
$_SESSION['echoable'] = $aVar; //put any variable you want here, such as POST data
Then, in the popup window, write:
EDIT: forgot to say, add this to the TOP of your page.
session_start();
Then do this stuff later on.
if((isset($_SESSION['echoable'])) && (!empty($_SESSION['echoable']))) {
echo $_SESSION['echoable'];
}
else {
echo "whatever"; // whatever you want here
}
The above will print whatever var you want. Hopefully this helps...if not let me know.
So there's this hyperlink - it's happy being a hyperlink - it does not want to change to a button or a form element - it wants to stay a link!
But it would really help me if I could submit it via GET or POST (something which I switch on my pages due to design criteria). Is there ANY way that I can do this
thanks
Giles
You're in luck... clicking a hyperlink already does a GET request.
If you want to add query parameters, append them to the query string like so:
link text
Assuming you already have a form that you want to submit, you can use JavaScript to make the link submit the form:
<form id="myform">
...
</form>
Submit
As you do not want to go for form elements, there is no need of using POST method.
Simply, what you can do is:
Link
And in the page_location page,
<?php
$foo = $_GET['foo']; //here, assigns $foo = bar
// required actions
?>
Hope you get the solution! :)
I'll assume you're not really using the link as a link... that you want to submit a form with it. You'll want to keep the link inside the form you want to submit, and you can do this (jQuery):
$('#link').parents('form').attr('method', 'GET').submit();
or
$('#link').parents('form').attr('method', 'POST').submit();