How to control the space between paragraph elements? - html

I have the following code here:
<div class="paper">
<h1>Welcome back, <?php echo $_SESSION["username"] ?>!</h1>
<p>This is your space, here are your stats:</p>
<p>Username: <?php echo $_SESSION['username']; ?> </p>
<p>Coins: <?php echo "$" . $_SESSION['coins']; ?> </p>
<?php if($admin){ echo "<p>Note: This account has admin access.</p>
<form action='admincontrol.php'>
<input type='submit' value='Admin Panel'/>
</form><br>"; } ?>
<form action="success.php" method="post" enctype="multi-part/form-data">
<input name="Logout" type="submit" value="logout">
</form>
</div>
And it displays like this:
How could I use my CSS to control the space within username and coins? It looks really awkward skipping and entire line to show coins.
So instead of:
Username: xflare
//Empty space
Coins: 100
It should be:
Username: xflare
Coins: 100
How could I do this using CSS?

You can either use one paragraph and use a <br> to get to the next line, or you could set the margin of the paragraph tags to 0px.

Related

New line in textarea <br> not interpreted

I am extremely tired = extremely stupid but I want to get on with this first thing in the morning...
<div class=' form-group smhTextArea removeForAjax' style='margin-bottom: 10px'>
<div class=''>
<textarea class='form-control message-text-area' rows='4'
name='message<?= $jj ?>' placeholder='New text box <?= $jj ?>'
id='message<?= $jj ?>' >
ID <?= $jj ?> "\n" <br> Msg:<?= $stackContent ?><br>
</textarea>
</div>
</div>
Output comes out as:
ID 1 "\n" <br> Msg:4 Mary had a little lamb it's... ??? # "<br>
I have looked at lots of answers on here and searched Google but can see nothing.
If this should work it is possibly that this is a very ill-formed test page at the moment.
Once again sorry if dumb but passing out here!
The <textarea> element does not render HTML, it actually renders plain text, as its formatted in HTML file. So that means you don't have to use <br /> tag to start a new line, instead just use the regular line break (press return key on keyboard).
<textarea>Line 1
Line 2
Line 4
</textarea>
You need to use a CR/LF
instead of a <BR>
<textarea> ID 1 "\n"
Msg:4 Mary had a little lamb it's... ??? # "</textarea>

Make html text not transform into html

So I have made a guestbook (http://guestbook.ssdfkx.ch) which has a bug I can't get rid of myself. When you submit an entry and write in HTML text, it is converted into HTML and not plain text. This leads to the problem that one person can mess up the whole website in seconds.
I have tried it with the <plaintext> tag. But if I do so, even when I close the tag again, everything from the tag down turns into plain text.
Help is appreciated. The following is my code:
while ($row = mysqli_fetch_object($ergebnis)) {
$message = $row->message;
$name = $row->name;
$date = $row->date;
$id = $row->id;
$datetime = new DateTime($date);
$formatteddate = $datetime->format('d.m.Y');
$formattedmessage = nl2br($message);
if ($_SESSION['logged_in'] == true) {
$entryfeld = '<article>
<div>
<main>
<div class="innerdiv">
<p>'.$formattedmessage.'</p>
</div>
</main>
<div class="innerleft">
<form method="POST">
<input name="id" type="hidden" value="'. $id . '"/>
<input name="löschen" class="deletebutton" id="deletebutton" value="Löschen" type="submit"> </form>
<br/>
<p id="innerleftp">'.$name.'</p>
</div>
<div class="innerrightdel">
<p>'.$formatteddate.'</p>
</div>
</div>
</article>';
EDIT: Well, the variable $formattedmessage is what the user enters. If the user enters HTML it actually converts it which should not be happening. I tried using the <plaintext> tag before and after the variable. It somehow changed everything after the variable into plain text and not only the user input.

Using tickboxes to select which class to use

I am just wondering if there is anyway to make it so that the css class of a DIV can be changed by the selection of a tick box.
For example I have this checkbox HTML
<input type="checkbox" name="size" id="portrait1" value="portrait"> Portrait
<input type="checkbox" name="size" id="landscape1" value="landscape"> Landscape
and then this div (used on concrete5 so might make no sense to some)
<div class="" style="display: none;">
<?php echo $form->label('content', t('Title'))
?>
<?php echo $form->text('content')
?>
<br>
<br>
<?php echo $al -> file('ccm-b-file', 'fID', t('Choose File'), $bf); ?>
<?php $bf = File::getByID($fID); ?>
<br>
<?php echo $form->label('UserURL', t('URL:'))
?>
<?php echo $form->text('UserURL')
?>
</div>
but i want it so that when I click portrait, for example, the class of that div changes to say portrait, any way of doing this?
You can do this with a bit of JavaScript.
You'll need to bind an event handler to your checkbox (that is, tell the browser to run a chunk of code when a certain event happens: the event in question being changing the state of the checkbox.)
(Note: I am using jQuery in my example for brevity.)
$("checkbox#portrait1").bind('change', function() {
$("div").toggleClass('portrait', $(this).is(":checked"))
});
The above example binds the given function to the "change" event of the given selector (input#portrait1, i.e. input element with the ID of portrait1).
When that event happens, it then "toggles" the class portrait on the div element based on whether the second argument is true or not, meaning if "this" (the checkbox input) is checked, then the class portrait will be added to that div (if not, remove the class of portrait).
Try this....
$('input[name=size]').click(function(){
if($(this).is(':checked'))
$('div').addClass('test')
else
$('div').removeClass('test')
})
Always have a default id for div like
<div class="" style="display: none;" id="a1">
<?php echo $form->label('content', t('Title'))
?>
<?php echo $form->text('content')
?>
<br>
<br>
<?php echo $al -> file('ccm-b-file', 'fID', t('Choose File'), $bf); ?>
<?php $bf = File::getByID($fID); ?>
<br>
<?php echo $form->label('UserURL', t('URL:'))
?>
<?php echo $form->text('UserURL')
?>
</div>
and in javascript
if(document.getElementById("portrait1").checked == true)
{
document.getElementById("a1").class="portrait";
}
else if(document.getElementById("landscape").checked == true)
{
document.getElementById("a1").class="landscape";
}

Joomla wraps content in <p> tags

I have Joomla 2.5 installed.
I developed some little module which generates html code.
Now, when it outputs the generated code, Joomla wraps it in <p> tags.
This causes two problems:
1. My css doesn't apply well because of paragraphing.
2. Paragraphs are crossing other tags.
For example here is a part of the module code:
<div class="formBlock">
<div class="label"><?php echo LABEL_PROJ_DESC; ?></div>
<textarea class="descbox"
id="descriptionBox"
name="rp_proj_desc"
cols="35"
rows="6"><?php echo $sender_description; ?></textarea>
</div>
<div class="formBlock">
<div class="label"><?php echo LABEL_PRODUCTS; ?></div>
<div class="formTable">
<?php
foreach($products as $id => $product)
{
$checked = "";
foreach($selectedProducts as $selectedId => $name)
{
if ($id == $selectedId)
{
$checked = "yes";
break;
}
}
?>
<div class="productsRow">
<span>
<input class="formCheckbox"
type="checkbox"
<?php
if ($checked)
{
echo "checked=yes ";
}
?>
name="<?php echo PROD_PREFIX . $id; ?>" />
</span>
<span class="productsName"><?php echo trim($product); ?></span>
</div>
<?php
}
?>
</div>
</div>
What I actually get is:
<div class="formBlock">
<div class="label">Your project description:</div>
<p> <textarea class="descbox"
id="descriptionBox"
name="rp_proj_desc"
cols="35"
rows="6"></textarea>
</div>
<div class="formBlock">
<div class="label">Our products you interested in:</div>
<div class="formTable">
<div class="productsRow">
<span></p>
<input class="formCheckbox"
type="checkbox"
name="product_0" />
</span>
<span class="productsName">Product1</span>
</div>
<div class="productsRow">
<span></p>
<input class="formCheckbox"
type="checkbox"
name="product_1" />
</span>
<span class="productsName">Product2</span>
</div>
<div class="productsRow">
<span></p>
<input class="formCheckbox"
type="checkbox"
name="product_2" />
</span>
<span class="productsName">Cheese</span>
</div>
</p>
</div>
</div>
Put attention to <p> and </p> tags.
If search amount of <p> and </p> elements in "view source" page it will:
<p> - 12
</p> - 18
It means that something really wrong happening with Joomla...
I guess that it is some plugin influencing it. I listed all plugins, especially those of type - "content" but didn't find any causing the problem.
These are the enabled plugins:
plg_editors-xtd_article
plg_finder_categories
plg_search_categories
plg_editors_codemirror
Xmap - Content Plugin
plg_finder_contacts
plg_search_contacts
plg_finder_content
plg_search_content
plg_system_debug
plg_content_emailcloak
plg_quickicon_extensionupdate
System - Gantry
plg_content_geshi
plg_system_highlight
plg_editors-xtd_image
Content - ITPShare
Editor - JCE
plg_authentication_joomla
plg_extension_joomla
plg_user_joomla
plg_quickicon_joomlaupdate
System - Jquery
plg_content_loadmodule
plg_system_log
plg_system_logout
AcyMailing Manage text
plg_finder_newsfeeds
plg_search_newsfeeds
plg_editors_none
AcyMailing Tag : Website links
plg_system_p3p
plg_content_pagebreak
plg_editors-xtd_pagebreak
plg_content_pagenavigation
plg_editors-xtd_readmore
plg_captcha_recaptcha
plg_system_redirect
AcyMailing : (auto)Subscribe during Joomla registration
plg_system_remember
System - RokExtender
plg_system_sef
AcyMailing : share on social networks
SIGE
AcyMailing : Statistics Plugin
AcyMailing table of contents generator
AcyMailing Tag : content insertion
AcyMailing Tag : Subscriber information
AcyMailing Tag : Manage the Subscription
AcyMailing Tag : Date / Time
AcyMailing Tag : Joomla User Information
AcyMailing Template Class Replacer
plg_editors_tinymce
plg_content_vote
plg_finder_weblinks
plg_search_weblinks
System - Shortcodes
Any ideas?
It's the editor (probably TinyMCE) that inserts these <p> tags. You should consider switching to "no editor" option (or another editor) - it can be set under "Global Configuration" screen, in the "Site" tab.
Also, in order to embed PHP code in your articles you should use a plugin such as DirectPHP.
Solved!!!
It was System - Shortcodes plugin of Zauan Shortcodes which distroyed my code.
Make sure that the textbox you created is not an RTF field.
If you use RTF field, then tags would be created automatically.

Displaying unnecessary HTML when showing content from MySQL database

My homepage pulls in content from my MySQL database to create a blog. I've got it so that it only displays an extract from the posts. For some reason it displays HTML tags as well rather than formatting it using the tags (See picture below).
Any help is appreciated.
Homepage:
<html>
<head>
<title>Ultan Casey | Homepage</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="wrapper">
<div id="upperbar">
Home
About Me
Contact Me
Twitter
<form id="search-form" action="/search" method="get">
<input type="text" id="textarea" size="33" name="q" value=""/>
<input type="submit" id="submit" value="Search"/>
</form>
</div>
<div id="banner">
<img src="images/banner.jpg">
</div>
<div class="sidebar"></div>
<div class="posts">
<?php
mysql_connect ('localhost', 'root', 'root') ;
mysql_select_db ('tmlblog');
$sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5";
$result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$date = date("l F d Y", $row['timestamp']);
$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$id = $row['id'];
?>
<?php echo "<p id='title'><strong>" . $title . "</strong></p>"; ?><br />
<div class="post-thumb"><img src="thumbs/<?php echo $id ?>.png"></div>
<?php echo htmlspecialchars(substr($entry, 0, 1050)) ?>...
<br>
<hr><br />
Posted on <?php echo $date; ?>
</p>
</div>
</div>
</p
<?php
}
?>
</div>
</div>
</div>
</body>
</html>
Image:
You're passing your post through htmlspecialchars, which encodes < as < and > as >, among other things. This means they display as < and > instead of being parsed as html tags.
The whole point of htmlspecialchars is to produce text that's inert in HTML... to make it display as-is.
A better way to do this is to NOT store <br /> (or any other html) in your post. Instead, use regular line breaks, and echo nl2br(htmlspecialchars($text)) into your page.
If you absolutely need to allow html, you might consider something like HTML Purifier to handle escaping nasty stuff, in which case you'd skip the htmlspecialchars call. Just beware: It's not a good idea to write your own filter to stop malicious code when displaying user-supplied HTML.
echo substr($entry, 0, 1050)