I'd like the following code to be change so that the textarea has a default value that disappears when it's focused.
if ($txtActive != 'N') {
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "";
echo "<tr>";
echo "<th align='" . $labelAlign . "'></th>";
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols'>" . stripslashes($value) . "" . "</textarea>";
echo ($txtError) ? "<br /><b style='color: $errorTxtColor;'>$txtError</b>" : '';
// echo "wendy TESTerburger";
echo "</td>";
echo "</tr>\n";
If I'm understanding the question properly, you would change this line, like so:
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "Default Text";
So if mod_SEF_textarea was not set, i.e. no value, the false clause would execute, which would be your default.
Any client side interaction won't use PHP - but your in client friend, JavaScript.
I wrote a jQuery plugin that does this in a cross browser fashion.
If only targeting modern standards compliant browsers, use the placeholder attribute.
You need to use the placeholder attribute. Note that it's part of the HTML5 spec, only works with the latest versions of some browsers. If you want it to work in older browsers, you'll need to do it with Javascript.
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' placeholder='Default text'>" . stripslashes($value) . "" . "</textarea>";
Here's an example of doing it with Javascript:
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Default value')this.value='';\" onblur=\"if(this.value=='')this.value='Default value';\">" . stripslashes($value) . "" . "</textarea>";
Very simple.
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value='Comments...' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Comments...')this.value='';\" onblur=\"if(this.value=='')this.value='Comments...';\">" . stripslashes($value) . "Comments..." . "</textarea>";
Related
Thank you for anyone who can help me with this!
What i have is an oracle database and i display all open work tickets using while and oci_fetch_row (page pickupready.php).
Each row is displayed in the table and has a checkbox to click on. User clicks multiple checkboxes selecting the rows (work tickets) they need and click Submit button.
New page (sendpickup.php) opens only showing table with rows that were selected by user. Then user has an ability to type quantity for each of the rows and then they click Send Pickup button which should email this output with their entered quantities and pickup times.
My question is how to grab everything that was output on that page + user edited information and email it using php mail() function?
This is my sendpickup.php page:
echo "<form action='' method='post'>";
echo "<table class = 'pickup'>\n";
echo "<tr style='background-color: orange'>\n";
echo "<th>CXL Date</th><th>Customer</th>";
echo "<th>WO #</th><th>Lot #</th><th>Style</th><th>Color</th><th>Original Qty</th>";
echo "<th>Cut Qty</th><th>Cut Date</th><th>Pickup Qty</th><th>Pickup Time</th>";
echo "</tr>";
echo "<tr style='background-color: #FFFFFF'>\n";
echo "<td>".($row[1] !== null ? htmlentities($row[1], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[2] !== null ? htmlentities($row[2], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[3] !== null ? htmlentities($row[3], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[4] !== null ? htmlentities($row[4], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[5] !== null ? htmlentities($row[5], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[6] !== null ? htmlentities($row[6], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[7] !== null ? htmlentities($row[7], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[8] !== null ? htmlentities($row[8], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[9] !== null ? htmlentities($row[9], ENT_QUOTES) : " ")."</td>\n";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = $row[8]></td>";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = '9 AM'></td>";
echo "</tr>\n";
echo "</table>";
echo "<input type='submit' name = 'sendpickup' value='Send Pickup'>";
echo "</form>";
Then i use following to send an email:
if (isset($_POST['sendpickup']))
{
$to = 'wip#abc.com';
$subject = 'READY FOR PICKUP';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: WIP <wip#abc.com>' . "\r\n";
$headers .= 'From: ABC User<wip#abc.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header( 'Location: pickupready.php');
}
Basically my page sendpickup.php works correctly, mail() function works too and my only problem is how to grab data for my $message variable.
i can use grab everything from sql output and assign to this variable but i cannot figure out how to send user information filled out in these 2 input boxes:
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = $row[8]></td>";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = '9 AM'></td>";
so as of right now i do something very basic. I select my output table by dragging mouse over it, then use a copy paste into email and email it manually. It works for time being but i really want to automate this and yet can't figure out how. I apologize if this was asked before - i tried to search but couldn't find any information and i cannot figure it out myself.
thank you again!
This is my javascript function.
<script>
function output($file_name, $content)
{
document.getElementById("content_title").innerHTML=" "+$file_name;
document.getElementById("content").innerHTML=" "+$content;
}
</script>
This is my PHP code;
<?php
$dir = "img_png";
$files = scandir($dir);
$dir_length = count($files);
?>
This is the second part of my PHP code (with problem); Problem: When $content="any string"; everything works properly, but when $content=file_get_contents('file'); my triggered function doesn't change any .innerHTML elements at all.
<?php
for ($i=2;$i<$dir_length;$i++){
$title=explode(".png", $files[$i]);
$content=file_get_contents('./content_txt/tv.txt');
echo "<td><button id='button' class='button' onClick=\"output('", $title[0],"";
echo "', '", $content,"";
echo "')\"><img src=\"/img_png/", $files[$i], "\"></img></button></td>";
}
?>
Start solving your issue with this (use dots instead of commas to concatenate strings)
<?php
for ($i=2;$i<$dir_length;$i++){
$title=explode(".png", $files[$i]);
$content=file_get_contents('./content_txt/tv.txt');
echo "<td><button id='button' class='button' onClick=\"output('" . $title[0];
echo "', '" . $content;
echo "')\"><img src=\"/img_png/" . $files[$i] . "\"></img></button></td>";
}
?>
Also I would set $content-variable outside the loop and skip the end-tag (it doesn't make any difference because </img> is not used):
Also encode your data when sending from php (with urlencode)
<?php
$content=file_get_contents('./content_txt/tv.txt');
for ($i=2;$i<$dir_length;$i++){
$title=explode(".png", $files[$i]);
echo "<td><button id='button' class='button' onClick=\"output('" . $title[0];
echo "', '" . urlencode($content);
echo "')\"><img src=\"/img_png/" . $files[$i] . "\"></button></td>";
}
?>
In your javascript you have to decode the content:
function output($file_name, $content)
{
$content = decodeURI($content);
document.getElementById("content_title").innerHTML=" "+$file_name;
document.getElementById("content").innerHTML=" "+$content;
}
Your file contents may contain line breaks or special characters that need escaping in JS, you will need to escape special characters before passing the string to the javascript function.
"tvvvvvv";
I suppose you copy-paste that string from PHP to tv.txt
Remove " and ; - you don't need it in file.
And " is your problem in javascript.
I have a huge list of stuff for a glossary ( about 17 pages worth ) that I have to put into an XML file. So I decided I'd use php to make it. My code works, except where ALL the XML code is, it doesn't show because it's trying to render it. Help?
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
I assume by render it you mean in your browser? If so, you'll need to escape the characters so they will be interpreted literally rather than as markup.
Check out htmlspecialchars and htmlentities
use CDATA construction:
echo "<desc><![CDATA[" . $arg[$i] . " - " . $arg[$i+2] . "]]></desc>";
If this is your entire script, fastest way would probably be to swap all of the <'s with <
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
So i installed XMAPP to view my php site im developing for a php mysql class at my local college and I ran aground hours ago and have been searching frantically for answers since. whenever i try to view my site all i see is this
" . $row['tid'] . ""; echo $id; $thisName = "\n
" . $row['fname'] . " " . $row['lname'] ."
"; echo $thisName; $description = "\n
" . nl2br($row['description']) . "
"; echo $description; echo ""; } include ("footer.php"); ?>
or something similar. we host on a local server that has everything we need but cannot access it from our homes. I was wondering if anyone could lend me a hand?
It looks like you have an echo statement where you're using a single quote to open a string but not close it. For instance:
echo '" . $row['tid'] . ""; echo $id; $thisName = "
Go search in your source for something like this. I'd bet that this is your error.
my question is how I can echo this the right way
because the variable in the onclick function gives out a undefined error
$openchat="<a href='javascript:void(0)' onClick='return chatWith(" . $livenaam .")'>" . $livenaam . "</a><br>";
echo $openchat;
I want to use it in a loop to get a list off users online for the chat
Thanks, Richard
Looks like you are missing some quotes:
$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . $livenaam ."\")'>" . $livenaam . "</a><br>";
or for increased security:
$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . htmlspecialchars($livenaam,ENT_QUOTES) ."\")'>" . htmlspecialchars($livenaam,ENT_QUOTES) . "</a><br>";
Try this:
'' . htmlspecialchars($livenaam) . '<br>'
If json_encode is not available, try this:
'' . htmlspecialchars($livenaam) . '<br>'