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();
?>
Related
thanks for your help in advance, noob here.
So, i have this error div of a form.
<div><?php echo $error; ?></div>
I'm trying to validate an email with php, but i want its error to change depending of the language selected by the user. I have another two php files with arrays with the translated text. What i'm tryng to do is to echo the error that contains the echo for the array variable so it can be interpreted as multilingual text in the html. I know that you can't echo an echo, but i need a workaround for this. Here is the php part.
<?php
$error = '';
if ($_POST) {
if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false) {
$error .= '<?php echo $lang["EMAIL_INVÁLIDO"]; ?>';
};
if ($error != "") {
$error = '<p>' . $error . '</p>';
};
};
?>
Thanks!
instead of direct echo, try assigning it to the variable and then echo the variable.
<?php
$error = '';
if ($_POST) {
if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false) {
$error .= $lang["EMAIL_INVÁLIDO"];
};
if ($error != "") {
$error = '<p>' . $error . '</p>';
};
};
?>
The following should suffice:
if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false) {
$error .= $lang["EMAIL_INVÁLIDO"];
};
You do not need to put quotation marks around variables(if you do they will be treated as text, not variables) and you were already working within <?PHP ?> tags.
instead just echo it later in the code:
<?php
$error = '';
if ($_POST) {
if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false) {
$error .= $lang["EMAIL_INVÁLIDO"];
}
if ($error != "") {
echo '<p>' . $error . '</p>';
}
}
?>
As you say, you can´t echo an echo because PHP is server-side. You must put your echo after you now the final value of error:
<?php
$error = '';
if ($_POST) {
if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false) {
$error .= '$lang["EMAIL_INVÁLIDO"]';
};
if ($error != "") {
$error = '<p>' . $error . '</p>';
};
echo $error;
};
?>
I have a page that displays my members information from a sql database. I have the output in the form of a shortcode but the information is displaying above the page content even though the shortcode is placed at the very bottom of the text editor. I know the problem is due to this code echoing instead of returning but I am a newbie to php and need help with syntax.
function listMembers() {
$sql1=mysql_query("select state_id,state_name from ".TABLE_STATE);
while($row1=mysql_fetch_assoc($sql1))
{
?> <a href="#" onclick="getDetails(
<?php echo $row1["state_id"];?>)"> <?php echo $row1["state_name"]; ?>
Here is all of the code
$sql1=mysql_query("select state_id,state_name from ".TABLE_STATE);
while($row1=mysql_fetch_assoc($sql1))
{
?> <?php echo $row1["state_name"]; ?> <?php
}
?><br/><br/><div id="resultDiv"></div><?php
}
add_shortcode('memberlist', 'listMembers');
function listRescueStandards() {
$display_members = '';
$sql = mysql_query("SELECT vc.*, s.*, m.*
FROM ".TABLE_COMPLIANCE." vc, ".TABLE_STATE." s, ".TABLE_MEMBERS." m
WHERE vc.member_id = m.cid
AND m.status = '1'
AND m.state = s.state_abbr
ORDER BY m.state, m.organization ASC");
while ($row = mysql_fetch_array($sql)) {
$organization = stripslashes($row['organization']);
if ($row['website']) {
$link = "<a href='http://".$row['website']."' target='_blank'>";
$endlink = "</a>";
} else {
$link = "";
$endlink = "";
}
if($x!=$row['state_name']){
$display_members .= "<br /><strong>".strtoupper($row['state_name'])."</strong><br />";
$x = $row['state_name'];
}
$display_members .= $link.$organization.$endlink."<br />
".stripslashes($row['address'])." ".stripslashes($row['address2'])."<br />
".stripslashes($row['city']).", ".stripslashes($row['state'])." ".$row['zip']."<br />";
if ($row['contact_name']) $display_members .= "Contact: ".stripslashes($row['contact_name']);
if ($row['contact_title']) $display_members .= ", ".stripslashes($row['contact_title']);
if ($row['phone']) $display_members .= "<br />Tel: ".stripslashes($row['phone']);
if ($row['fax']) $display_members .= "<br />Fax: ".stripslashes($row['fax']);
if ($row['email']) $display_members .= "<br />".$row['email'];
if ($row['website']) $display_members .= "<br /><a href='http://".$row['website']."' target='_blank'>".$row['website']."</a>";
if ($row['year_est']) $display_members .= "<br />Founded in ".$row['year_est'].".";
if ($row['org501c3'] == "1") $display_members .= "<br />This organization IS registered with the IRS as a 501(c)3.";
if ($row['org501c3'] != "1") $display_members .= "<br />This organization is NOT registered with the IRS as a 501(c)3.";
$display_members .= "<br /><br />";
}
return "<div class='memberlist'>" . $display_members . "</div>";
}
add_shortcode('standardslist', 'listRescueStandards');
?>
Thank you in advance for your help! I appreciate anyone looking at this and if you need clarification, please let me know!
Ah OK. according the shortcodes api you want to be returning a value, not echoing it. you can use output buffering to convert an echo type of code to a return type. This entails simply wrapping all of your echo statements in ob_start() and ob_end_clean()
function listMembers() {
$sql1=mysql_query("select state_id,state_name from ".TABLE_STATE);
ob_start(); //send all future echo statements to the buffer instead of output
while($row1=mysql_fetch_assoc($sql1))
{
?> <?php echo $row1["state_name"]; ?> <?php
}
?><br/><br/><div id="resultDiv"></div><?php
$result=ob_get_clean(); //capture the buffer into $result
return $result; //return it, instead of echoing
}
Its been a while since the last time I was coding, and I am a little rusty. I am trying to parse an xml file and having a problem with the condition. Spent hours trying to figure out where is the problem, but without success...
PHP CODE:
<div id="gallery">
<?php
$cat_img="images/cat.png";
$logo_path="logos/";
$file = simplexml_load_file('stores.xml');
$old_cat="";
foreach($file->store as $store){
if($store->cat != $old_cat){
echo "<img id='cat' src='".$cat_img."'><div id='cat_text'>".$store->cat."</div><br>";
$old_cat=$store->cat;
}
echo "<div id='store'><img id='store_img' src='".$logo_path.$store->logo."' alt='logo'><br>";
echo "<store_name>".$store->name."</store_name>";
echo "<phone>".$store->phone."</phone><phone>טל: </phone></div>";
}
?>
</div>
STORES.XML
<?xml version="1.0" encoding="UTF-8"?>
<stores>
<store><logo>renuar.jpg</logo>
<name>renuar</name>
<phone>052-6059962</phone>
<cat>clothing</cat></store>
<store><logo>yoop.jpg</logo>
<name>YOOP</name>
<phone>08-6601451</phone>
<cat>clothing</cat></store>
....
</stores>
The idea is to print every store, when category changes it should print the category divider and keep printing the stores. Somehow the condition is always true and I have no idea why...
p.s
If anyone has a better idea on how to divide the categories, a different method, I would be happy to hear.
Thanks!!!
$store->cat will be SimpleXMLElement object and two object will not be same even with same category name. You need to cast it to string for comparison
Like (string) $store->cat, try this:
<?php
$cat_img = "images/cat.png";
$logo_path = "logos/";
$file = simplexml_load_file('test.xml');
$old_cat = "";
foreach ($file->store as $store) {
if ((string) $store->cat != $old_cat) {
echo "<img id='cat' src='" . $cat_img . "'><div id='cat_text'>category: " . $store->cat . "</div><br>";
$old_cat = (string) $store->cat;
}
echo "<div id='store'><img id='store_img' src='" . $logo_path . $store->logo . "' alt='logo'><br>";
echo "<store_name>" . $store->name . "</store_name>";
echo "<phone>" . $store->phone . "</phone><phone>טל: </phone></div>";
}
?>
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
<? echo $rows['general']; ?><? echo $rows['comment']; ?>
'general' is a text field but 'comment' is a checkmark item. It works fine if I type in the text field or if I select the checkmark; but if I fill the text form and also check the checkmark then I would like them to be separated with a comma and space.
$separation = "";
if(!empty($rows['general']) && !empty($rows['comment'])) {
$separation = ", ";
}
echo $rows['general'] . $separation . $rows['comment'];
if thous are the only 2 field:
echo implode(',', array_filter($rows));
otherwise you can use trim to remove the , if not needed:
echo trim("{$rows['general']},{$rows['comment']}", ', ');
Something like this?
if (($rows['general'] != "") && ($rows['comment'] != "")) {
echo $rows['general'] + ", "+ $rows['comment'];
} else {
echo $rows['general'] + $rows['comment'];
}