I'm really scratching my head...
I'm trying to add a class to my input and textarea fields, but whenever I do it like this:
$inputclass = $class." multilanginput";
the second part is not appended, but when I leave out the space and do it like this:
$inputclass = $class."multilanginput";
it works just fine...
i've never had this issue before, any ideas what's going wrong?
it's part of this little function:
function backend_dynamic_dialoginput($label,$class,$type = 'single',$lang = "none"){
if($lang == "none"){
$lang = "";
}
else{
$lang = "_".$lang;
}
$class = $class.$lang;
$id = "";
if($type == "singleint" || $type == "multiint"){
$id = $class."_m";
$inputclass = $class." multilanginput";
}else{
$inputclass = $class;
}
$html = "
<div style='padding-left:10px;margin-top:1px;background-color:#dddddd;padding-bottom:8px;padding-top:8px;'>
<div style='float:left;font-size:13px;color:#5a5a5a;padding-top:6px;margin-bottom:2px;width:30%;text-align:right;padding-right:4px;' class='font_lato'>".$label."</div>
";
if($type == "single" || $type == "singleint"){
$html .= "<input type='text' value=".$inputclass." style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."'>";
}
else if($type == "multi" || $type == "multiint"){
$html .= "<textarea style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."' rows=2></textarea>";
}
$html .= "
";
if($type == "singleint" || $type == "multiint"){
$html .= "<div style='float:right;font-size:12px;background-color:#eeeeee;margin-right:4px;' id='".$class."' class='togglefullscr font_lato'>Int.</div>";
}
$html .= "
</div>";
if($type == "singleint" || $type == "multiint"){
$html .= backend_dynamic_internationaldialog($label,$class,$type);
}
return $html;
}
You have not put quotes around the HTML attribute.
Change the line to:
$html .= "<input type='text' value='".$inputclass."' style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."'>";
When you omit the quotes like this, the second class name will be treated as another property.
Problems like this can be easily avoided if you validate your markup ;-)
Your quotation marks are wrong:
$html .= "<input type='text' value=".$inputclass."
It has to be $html .= "<input type='text' value='".$inputclass."' or $html .= "<input type='text' value=\"".$inputclass."\".
However, I strongly recommend using single quotes for strings:
$html .= '<input type="text" value="'.$inputclass.'"...>';.
You can escape spaces using \x20 and \040 in php.
http://php.net/manual/en/regexp.reference.escape.php
Please see the manual
Related
the situation I am facing is like that:
I read data from a database and dump them into a table in a webpage. And then, according to a column's value, show a drop-down list or not. And write the value from the drop-down list back into the database.
I use ...Submit, but the $_GET has no values about the drop-down list.
I list the whole code set here.
Any help is highly appreciated!
$GCdataSQL = "select * from table_name";
$GCdata = new Query($GCdataSQL);
$table = "<form method='GET'><table class='datatable table table-condensed ' id='query-data'><thead><tr>";
$ColName = array('col1','col2','col3','col4', 'col5', 'col6', 'col7', 'col8');
foreach ($ColName as $Name){
$table .= "<th>$Name</th>";
}
$table .= "</tr></thead><tbody>";
while ($GCdataRow = $GCdata->fetchRow()){
$emplid = $GCdataRow['emplid'];
$term = $GCdataRow['term'];
$handled = $GCdataRow['handled'];
if ($GCdataRow['code'] == 'UNKNOW' || $GCdataRow['code'] == 'Not Repeated'){$GCdataRow['code']= '';}
if ($GCdataRow['local_action'] !== $GCdataRow['new_action']){
$table .= "<tr bgcolor= 'LightPink'>";
}
else {
$table .= "<tr>";
}
foreach($GCdataRow as $key=>$value){
if ($key == 'emplid'){
$table .="<td><a href='link' target = '_blank'>$value</a></td>";
}
else if ($key == 'new_action'){
$table .="<td><a href='link' target = '_blank'>$value</a></td>";
}
else if ($key == 'handled' && $handled == 'Not Reviewed'){
$table .="<td><select name = 'handlecode'><option value = 'Not Reviewed'>Not Reviewed</option><option value = 'Handled by Script'>Handled by Script</option><option value = 'Handled Manually'>Handled Manually</option><option value = 'Leave It'>Leave It</option></select></td>";
}
else {
$table .= "<td>".htmlentities($value)."</td>";
}
}
$table .= "</tr>";
$loopcount++;
}
if(isset($table)) {$table .= "</tbody></table>";}
echo $table;
echo "<button type='submit' class = 'btn btn-primary' style = 'position: absolute; left:50%;' >Submit</button></form>";
finally I changed the form method to POST, and everything is fine! Now the values are in $_POST, and I could use them to insert into the database!
Thank you!
I'm getting data from this function, now I want checked checkboxes based on my condition and my condition is if I got value roro from db no will be checked if I got Vessel, Containerized yes will be checked.
$getDataForPDF = getDataForPDF($bookingsId, $bookingsLettersDockReceiptId);
if($getDataForPDF["typeOfMove"] == "Vessel, Containerized") {
$checkedYes = "checked";
} if($getDataForPDF["typeOfMove"] == "roro") {
$checkedNo = "checked";
}
and I'm using this condition in checkboxes
$html .= '<tr>';
$html .= '<td colspan="3">';
$html .= '<small>11. TYPE OF MOVE</small> <br />';
$html .= $getDataForPDF["typeOfMove"];
$html .= '</td>';
$html .= '<td colspan="2">';
$html .= '<small>11a. CONTAINERIZED (Vessel only)</small> <br/>';
$html .= '<input type="checkbox" checked="'.$checkedYes.'" name="yes"> Yes <input type="checkbox" checked="'.$checkedNo.'" name="no"> No';
$html .= '</td>';
$html .= '</tr>';
my condition is right but not working on checked="checked" condition. What is wrong in my code?
The checked property is as simple as adding checked at the end of the tag. For example <input type="checkbox" name="yes" checked> would be a checked box where the absence of checked would be unchecked.
The following code should solve the problem for you:
$checkedYes = '';
$checkedNo = '';
$getDataForPDF = getDataForPDF($bookingsId, $bookingsLettersDockReceiptId);
if($getDataForPDF["typeOfMove"] == "Vessel, Containerized") {
$checkedYes = " checked";// note the space before checked
} if($getDataForPDF["typeOfMove"] == "roro") {
$checkedNo = " checked";// note the space before checked
}
$html .= '<tr>';
$html .= '<td colspan="3">';
$html .= '<small>11. TYPE OF MOVE</small> <br />';
$html .= $getDataForPDF["typeOfMove"];
$html .= '</td>';
$html .= '<td colspan="2">';
$html .= '<small>11a. CONTAINERIZED (Vessel only)</small> <br/>';
$html .= '<input type="checkbox" name="yes"'.$checkedYes.'> Yes <input type="checkbox" name="no"'.$checkedNo.'> No';
$html .= '</td>';
$html .= '</tr>';
JSFiddle: http://jsfiddle.net/o984L61e/
Edit
Try changing the top code block to:
$checkedYes = '';
$checkedNo = '';
$getDataForPDF = getDataForPDF($bookingsId, $bookingsLettersDockReceiptId);
if($getDataForPDF["typeOfMove"] == "Vessel, Containerized") {
$checkedYes = " checked='checked'";// note the space before checked
}
if($getDataForPDF["typeOfMove"] == "roro") {
$checkedNo = " checked='checked'";// note the space before checked
}
The examples on tcpdf use the checked='checked' property just like the other answers had, but you must initialize the variables before you try to concatenate in the html string. As written in the question, either $checkedYes or $checkedNo will be undefined since they are being initialized in mutually exclusive if blocks. Not sure if this will make a difference but it seems plausible.
Could you try?
$getDataForPDF = getDataForPDF($bookingsId, $bookingsLettersDockReceiptId);
if($getDataForPDF["typeOfMove"] == "Vessel, Containerized") {
$checkedYes = "checked='checked'";
} elseif($getDataForPDF["typeOfMove"] == "roro") {
$checkedNo = "checked='checked'";
}
Along with:
$html .= '<input type="checkbox" '.$checkedYes.' name="yes"> Yes <input type="checkbox" '.$checkedNo.' name="no"> No';
I'm not sure it'd solve your problem but that is what you want to do in order the check the checkboxes accordingly to your database info.
Does it help?
TCPDF's writeHTML() function only supports a limited subset of HTML tags. Check the writeHTML() documentation for details. The input tag is apparently one that is not supported.
Instead, you could use HTML entities to represent the checked and unchecked checkboxes. There's already a StackOverflow question that gives examples of possible entities you could use.
Following is an ajax post page which renders the checkboxes on run-time. I am facing issue while writting the script for select all button, when I click on the button only 1 value is getting selected not the entire array:
<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
include("../includes/functions.php");
if(isset($_REQUEST['t']))
{
$td = $_REQUEST['t'];
$t = split(",",$td);
$all = "";
$box_in_row = 0 ;
$this_box="<table border=0><tr>";
foreach($t as $table)
{
$this_box = "<td><h3>$table</h3>";
$result = mysql_query("SHOW FULL COLUMNS FROM $table FROM prfxcom1_prfx");
$options = "";
while($r = mysql_fetch_object($result))
{
if(!empty($r->Comment))
{
$options .= "<br><input type=checkbox name=\"".$table."[]\" value='$r->Field' id=\"$table\">" . $r->Field;
}
}
if($table == "transfer_req")
{
$options .= "<br><input type=checkbox name=\"".$table."[]\" value='Net Profit' id=\"$table\">NetProfit";
}
$this_box .= $options;
// Button
$click = "$('#$table').attr('checked', 'checked')";
$button = "<br /><input style='margin-top:10px;' type='button' name='$table_button' id='$table_button' value=' Select All ' onclick=\"$click\"/>";
$all .= "<div class='tblBox'>".$this_box.$button."</div></td>";
}
//$all = "<table class=\"listing form\" cellpadding=\"0\" cellspacing=\"0\">".$all."</table>";
echo $all;
}
?>
Issue is faced in the line:
$click = "$('#$table').attr('checked', 'checked')";
Please suggest, I am stuck on this.
Thanks,
Hardik
WHAT???
$click = "$('#$table').attr('checked', 'checked')";
How can you write Javascript in the middle of a PHP file? It needs to be in script tags but even then PHP runs at the server and will not render your Javascript for you.
Add script tags, change your ID's to separate ones and give them the same class like tableClassName, and then write the following.
$(function(){
$('.tableClassName').attr('checked', 'checked')";
});
Ignoring the many issues with the code and simply answering the question:
You need to refer to the checkboxes using a class name not a ID (you have given them all the same ID)
For these lines: $options .= "<br><input type=checkbox name=\"".$table."[]\" value='$r->Field' id=\"$table\">" . $r->Field;
Change to: $options .= "<br><input type=checkbox name='" . $table . "[]' value='" . $r->Field ."' class='" . $table . "'>" . $r->Field;
For this line: $click = "$('#$table').attr('checked', 'checked')"; use single quotes or escape the $
Change to: $click = '$("."'.$table.'").attr("checked", "checked")';
Can someone tell me how can I make this code under one textarea. I'm fairly new to php so any bit of advice would be helpful thanks.
if ($test != "")
print("<p>" . format_comment($test) . "</p>\n");
if ($test1 != "")
print("<p>" . format_comment($test1) . "</p>\n");
Cheers.
This is very easy to achieve, try it like this:
// Print the top
print("<p><hr>");
// Print $text if set
if ($test != "")
print(format_comment($test));
// Print $text1 if set
if ($test1 != "")
print(format_comment($test1));
// Print the bottom
print("<hr></p><br />");
Altough, I recommend you to use echo instead of print, because echo is a more common used function. Using echo you can do it like this:
echo "<p><hr>";
if ($test != "")
echo format_comment($test);
if ($test1 != "")
echo format_comment($test1);
echo "<hr></p><br />";
I might understood your question wrong, if you just want to put the content from the variables into a text area, you can do it as follows:
$content = "";
if ($test != "")
$content .= "<p><hr>" . format_comment($test) . "<hr></p><br />";
if ($test1 != "")
$content .= "<p><hr>" . format_comment($test1) . "<hr></p><br />";
echo "<textarea>" . $content . "</textarea>";
EDIT: It looks like you've used \n to get a new line, you should use <br /> instead in HTML. Simply replace all the \nparts with <br /> to fix the problem.
Hope this helps!
You may try by concatenating both content
<?php
require "include/bittorrent.php";
dbconn();
stdhead("Tags");
begin_main_frame();
begin_frame("Tags");
$test = $_POST["test"];
$test1 = $_POST["test1"];
$content="<p><hr>";
if ($test != "")
$content .= format_comment($test);
if ($test1 != "")
$content .= format_comment($test1);
$content=$content. "<hr></p><br />";
?>
<textarea id="test" name="test"><?php echo $content; ?></textarea>
<?php
end_frame();
end_main_frame();
stdfoot();
?>
I have created a CheckModulePermission function in my user class which checks a module table to ensure the user has permissions to view the page. Below is the function
public function CheckModulePermissions($moduleId) {
if(isset($_SESSION['userId'])) {
// If the user is admin, allow regardless
if($this->IsAdmin()) {
return true;
}
$sql = "SELECT `userModuleId`
FROM `userModules`
WHERE `userId` = " . $_SESSION['userId'] . "
AND `moduleId` = " . $moduleId . ";";
mysql_select_db(DB_USER_DATABASE_NAME, $this->conn);
$result = mysql_query($sql, $this->conn);
$x = mysql_fetch_row($result);
if($x[0] == 1) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
This works fine in all my pages except one page where it fails . I have a dropdown box and a text box which will be updated depending on the users permission. The user i am logged on as has the permission but the dropdown boxes do not appear.
if(isset($_GET['orderNumber'])) {
// If post is set then update the prima reference and order status
// Only if user has sufficient privileges
if(isset($_POST['orderStatus'])) {
if($user->CheckModulePermissions(11)) {
$cid->UpdateOrderStatus($_GET['orderNumber'], $_POST['orderStatus']);
$cid->UpdateOrderReference($_GET['orderNumber'], $_POST['PReference']);
}
}
if($user->CheckModulePermissions(11)) {
$content .= "<select name='orderStatus'>
<option value='1'";
if($orderDetails['status'] == 1) $content .= " selected='selected'";
$content .= ">Incomplete</option>
<option value='2'";
if($orderDetails['status'] == 2) $content .= " selected='selected'";
$content .= ">Submitted</option>
<option value='3'";
if($orderDetails['status'] == 3) $content .= " selected='selected'";
$content .= ">Processed</option>
</select>";
} else {
if($orderDetails['status'] == 1) $content .= "Incomplete";
if($orderDetails['status'] == 2) $content .= "Submitted";
if($orderDetails['status'] == 3) $content .= "Processed";
}
$content .= "</td>
</tr>
<tr>
<th>Prima Order Number</th>
<td>";
if($user->CheckModulePermissions(11)) {
$content .= "<input type='text' name='pReference' value='" . $orderDetails['PReference'] . "' /></td>
</tr>
<tr>
<td colspan='2'><input type='submit' /></td>
</tr>";
} else {
$content .= $orderDetails['PrimaReference'] . "</td></tr>";
}
$content .= "</table>
</form>
</td>
Is it the logic for the dropdown box where it fails?
Here is a more efficient/readable version of your CheckModulePermissions() method...
public function CheckModulePermissions ($moduleId) {
// Deny immmediately if no userId is set
if (!isset($_SESSION['userId'])) return FALSE;
// If the user is admin, allow regardless
if ($this->IsAdmin()) return TRUE;
// Generate an SQL statement - does this need sanitising?
$sql = "SELECT `userModuleId`
FROM `userModules`
WHERE `userId` = '{$_SESSION['userId']}'
AND `moduleId` = '$moduleId'
LIMIT 1";
// Is this line really necessary? Are you actually working with more than one database?
// Even if you are, it's probably better to do it in the query, like this:
// SELECT whatever FROM DB_USER_DATABASE_NAME.tablename WHERE...
mysql_select_db(DB_USER_DATABASE_NAME, $this->conn);
// Since you only want one row, it's slightly more resource efficient
// to abandon the $result variable
$x = mysql_fetch_row(mysql_query($sql, $this->conn));
// This means the same thing as your if ... else
return $x[0] == 1;
}
...and here is a rewritten version of the HTML generation code.
// Get this once, at the beginning, to minimise SQL traffic
$hasPermissions = $user->CheckModulePermissions(11);
// Uncomment this line to make sure that $user->CheckModulePermissions is returning the value you expect
//var_dump($hasPermissions);
if (isset($_GET['orderNumber'])) {
// If post is set then update the prima reference and order status
// Only if user has sufficient privileges
if (isset($_POST['orderStatus']) && $hasPermissions) {
$cid->UpdateOrderStatus($_GET['orderNumber'], $_POST['orderStatus']);
$cid->UpdateOrderReference($_GET['orderNumber'], $_POST['PReference']);
}
// Map of status numbers to string descriptions
$statusStrs = array(1 => 'Incomplete','Submitted','Processed');
if ($hasPermissions) {
// Generate a <select>
$content .= "<select name='orderStatus'>";
foreach ($statusStrs as $val => $str) {
$content .= "\n<option value='$val'".(($orderDetails['status'] == $val) ? " selected='selected'" : '').">$str</option>";
}
$content .= "\n</select>";
} else {
// Print the current status string
$content .= $statusStrs[$orderDetails['status']];
}
// Close the table cell (layout tables are nasty nasty)
$content .= "</td>
</tr>
<tr>
<th>Prima Order Number</th>
<td>";
if ($hasPermissions) {
// add an input for changing the reference number
$content .= "<input type='text' name='pReference' value='{$orderDetails['PReference']}' /></td>
</tr>
<tr>
<td colspan='2'><input type='submit' /></td>
</tr>";
} else {
// Display the current reference number
$content .= $orderDetails['PrimaReference'] . "</td></tr>";
}
$content .= "</table>
</form>
</td>
I think the most likely cause of your problem is that CheckModulePermissions() is returning FALSE when you expect it to return TRUE. Uncomment the var_dump() line to verify this and we'll take it from there.