I am trying to add bullets to my defined texture output. I simply created a textarea in php with some preset text. How can I preface each piece of preset text with a bullet. I want the text in my textarea to look like this:
Name:
Address:
DOB:
Favorite Drink:
Here is my PHP code:
<?php
echo "<textarea name='' id='' style='width: 565px;' rows='8' cols='60'>";
echo "Name:";
echo "Address:";
echo "DOB:";
echo "Favorite Drink:";
echo "</textarea>";
?>
Thanks so much for your help!
If you must use a textarea, you can add the 'bullet' HTML entity in the string...
<?php
echo "<textarea name='' id='' style='width: 565px;' rows='8' cols='60'>";
echo "• Name:";
echo "• Address:";
echo "• DOB:";
echo "• Favorite Drink:";
echo "</textarea>";
?>
Otherwise, you can go with an unordered list as #Tim Hunter suggested:
<?php
echo "<ul>";
echo "<li>Name:</li>";
echo "<li>Address:</li>";
echo "<li>DOB:</li>";
echo "<li>Favorite Drink:</li>";
echo "</ul>";
?>
To write something in text area with bullets prefix, I code it with div instead of textarea, follow the below code snippets.
<?php
echo '<div class="editable" contenteditable="true">
<ul>
<li>List item1</li>
<li>List item2</li>
<li>List item3</li>
......
<li>List item(n)</li>
</ul>
</div>';
?>
I don't think it's possible to add bullet points inside a regular textarea. You could make an editable section or div with bullet points in it, but I don't think this works well with a form.
Also, putting the bullet points inside the textarea will allow users to delete them.
Since I assume you would be submitting the input in a form at some point, why not use regular inputs wrapped in li elements? That way, you can use the inputs in a submittable form, and the bullet points can't be deleted.
You can even style it to look like one big textarea!
<style>
#form { border: solid #666 1px; border-radius: 3px; }
#form input { border: 0; -webkit-appearance: none; background-color: unset; }
#form input:focus { outline: none; }
</style>
<form id="form">
<ul>
<li>Name: <input type="text" placeholder="Name"></li>
<li>Address: <input type="text" placeholder="Address"></li>
<li>DOB: <input type="text" placeholder="DOB"></li>
<li>Favorite Drink: <input type="text" placeholder="Favorite Drink"></li>
</ul>
</form>
http://jsfiddle.net/7tw21m3o/ <--- in action
Related
I'm currently developing a simple web page that enables the user to: upload an image and a corresponding caption to a DB, let the user view the images and delete them.
I have already accomplished the first two with the following code:
<?php
#include_once("connection.php");
$db = new mysqli("192.168.2.2", "root", "", "proyectoti");
if ($db->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo "Información de servidor: ";
echo $db->host_info . "\n";
// Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); #$_FILES['image']['name'];
// Get text
$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
$sql = "INSERT INTO images (image, image_text) VALUES ('{$image}', '{$image_text}')";
// execute query
mysqli_query($db, $sql);
}
$result = mysqli_query($db, "SELECT * FROM images");
?>
<!DOCTYPE html>
<html>
<head>
<title>Proyecto TI | Sube imágenes</title>
<style type="text/css">
#content{
width: 50%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 5px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
float: left;
margin: 5px;
width: 300px;
height: 140px;
}
</style>
</head>
<body>
<h1>Proyecto TI | <a> Interfaz </a></h1>
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
#echo "<img src='images/".$row['image']."' >";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'"/>';
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
?>
<form method="POST" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea
id="text"
cols="40"
rows="4"
name="image_text"
placeholder="Di algo de esta imagen ^^"></textarea>
</div>
<div>
<button type="submit" name="upload">Publicar</button>
</div>
</form>
</div>
</body>
</html>
It looks like this:
Now, the only part I'm missing is being able to delete an image (basically I only echo each image), how would you suggest for me to accomplish this, to make each item clickable and let's say, pop up a dialog or button to perform an action (delete from DB).
I really don't know much about PHP or CSS/HTML, any help would be much appreciated, Thank you!
Within this loop:
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
#echo "<img src='images/".$row['image']."' >";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'"/>';
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
?>
Personally I would add an element to click on - like an 'x' or whatever - with a unique data attribute:
https://www.abeautifulsite.net/working-with-html5-data-attributes
You have to add the unique id of the image obviously, so you can let SQL know which row to delete... Like this:
echo "<div class='delete-image' data-id='" . $row['id'] . "'>x</div>';
Then I would link this class to an AJAX call to make an asynchronous request to the server and delete the image without reloading the page. It's not very hard.
An easier solution would be to create a new form in the loop, so you create multiple forms per image, add a hidden field with the image id in the form and make a submit button with the valeu 'delete' or simply 'x'.
The same way you created the check:
if (isset($_POST['upload'])) { ... }
You can create something like this:
if (isset($_POST['delete-image'])) { ... }
You will be carrying the image id value like a normal form input. And you can do whatever you want with it.
I would HIGHLY suggest you to look into how to work with jquery and ajax calls though.
Opening a dialogue and ask the user before he deletes an item will require that you either go another page for deletion or use javascript for this.
In both cases, you should somehow set an identifier for your image in your html-code.
I would suggest you give every image an id
'<img ... id="'.$yourImageId.'">'
or a data-attribute
'<img ... data-identifier="'.$yourImageId.'" >'
with that identifier.
First variant:
...
echo '<a href="/path/to/delete/view/page.php?image=yourImageId">'
echo '<img ... id="'.$yourImageId.'"/>'
echo '</a>'
...
and on this delete-view-page, you just have a form that triggers your delete-code
<form action="/path/to/delete/view/page.php" method="POST">
<input type="hidden" name="id" value="<?php echo $yourImageId ?>">
</form>
<!-- after this, react with $_POST['id'] --> to the id sent to the server side and delete the image in your database -->
The other way is not server side rendered.
You should give your Elements some class like "my-clickable-image".After that, you have a script on your page, that looks something like the following
<script>
/* get your images with querySelectorAll, the . stands for class and after that your name */
var clickables = document.querySelectorAll(".my-clickable-image");
clickables.foreach(function(image){
// say that for each image, when clicked the generated function is called image.addEventListener('click',generateShowDialogueFunc(image.getAttr("id")));
});
// generate a function(!) that reacts to an image being clicked
function generateShowDialogueFunc(imageIdentifier){
// return a function that adds a Pop Up to the page
// the Pop Up has approximately the code of the first options second page
// except that now, it must create and remove elements in javascript
return function createPopUp(){
removePopUp();
var popup = document.createElement("div");
popup.setAttribute("id","deletePopUp");
var deleteForm = document.createElement("form");
deleteForm.setAttr("action","/path/to/file/that/deletes/given/query.php?id="+imageIdentifier);
var deleteContents = '<p> Do you want to delete this image? </p>'
+ '<button type="submit"> yes </button>'
+ '<button onclick="removePopUp()"> no </button>'
deleteForm.innerHTML = deleteContents;
document.body.appendChild()
}
}
// remove the Pop Up that can be used to delete an image from the page
function removePopUp(){
var existingPopUp = document.getElementById("deletePopUp");
if(existingPopUp) document.body.removeChild(existingPopUp);
}
</script>
<!-- just add some styling to make the popup show on top of the page -->
<style>
#deletePopUp{
width: 50vw;
height: 50vh;
position: absolute;
z-index: 1;
padding: 1em;
}
</style>
In this case, you just call the server to delete the image, not to show the delete form.
I would suggest the second one but stack overflow is not made for opinion based answers.
Regarding simple security:
It looks like your users could give titles or texts to images.
try what happens if a user gives a title like <bold>some title</title>
and guess what would happen if the title is <script>window.location.href="google.com"</script>
(XSS * hint hint *)
Regarding code structure:
If you want to do something like web development more often, think about separating your database accessing code, and your logic code from your php page template code, this is called 3 tier architecture and standard for bigger projects but i guess this is really just a first, short prototype or test.
I have this list in welcome.php
<li>
<img src="images/referral.png" > Referral
</li>
Here I am trying to populate the circle with value from database. I am getting the right value, but its not appearing in the circle. Pardon my CSS please.
Copied this code from here http://www.cssportal.com/blog/create-css-notification-badge/
In the same welcome.php, CSS code is
.badge1 {
position:relative;
}
.badge1[data-badge]:before {
content:attr(data-badge);
position:absolute;
top:0px;
right:0px;
font-size:.7em;
background:green;
color:white;
width:18px;height:18px;
text-align:center;
line-height:18px;
border-radius:50%;
box-shadow:0 0 1px #211;
}
The php value I am trying to echo here comes from a php block after this code.
Code is:
<html><li>
<a href="#" class="badge1" data-badge="<?php echo "$row_cnt"; ?>" value = "
<?php echo "$row_cnt"; ?>"><img src="images/referral.png" > Referral</a>
</li>
</html>
<?php
// Get $row_cnt
?>
So how do I access this $row_cnt value above?
Any help would be helpful.
Remove quotation marks:
<?php echo $row_cnt; ?>
or even
<?=$row_cnt?>
You can not put " inside " so use the escape \ before it
or remove it in echo before the variable
I have a problem with not working "first-child". I want to make top of christmas tree as red so first div.main have to be div with red background.
And another problem is that if I set amount of the height of this tree over 70 the next char is in next line but want to stay this div in line over and scroll it in this case.
Sorry for not English name of Variables
<html>
<head>
<style>
div.center {
border:2px solid black;
display:block;
}
div.main{
display:inline-block;
color:green;
}
div.main:first-child {
background-color:red
}
</style>
</head>
<body>
<form action="choinka.php" method="GET">
wysokość: <input type="text" name="tak">
<input type="submit" value="dawaj">
</form>
<?php
$tak = $_GET['tak'];
echo " wysokosc to: $tak";
echo '<div class="center>";
for($wysokosc = $_GET['tak']; $wysokosc >= 0;$wysokosc--){
echo "<br>";
for($szerokosc = 0; $szerokosc <= $wysokosc ; $szerokosc++){
echo " "; //spacja szerokosc 1em
if($szerokosc == $wysokosc)
for($znaki = $_GET['tak']; $znaki >= $wysokosc ; $znaki--){
echo '<div class="main">  ⊗</div>';
}
}
};
echo "</div><br><br>";
?>
Please try div.main:first-of-type instead of div.main:first-child as you can see loop append a <br></br> before main and :first-child get <br> as the first child.
This will do the trick Check Image
I would like to produce an application form, written in PHP and CSS, and my problem is this: In the tag, I set up a submit button, and upon writing my name into the text bar, I get the sentence "The name that I have entered is: " at the TOP LEFT of my web page. I don't want this this sentence at the top of my page. I want this sentence BELOW the text box into which I enter my name. Having the sentence appear at the top of my web page means a badly designed web pae, but I don't know how to make this sentence appear where I want it to appear. OK, when I get rid of all the other codes (ie CSS codes etc) in my program and just have the tag all by itself (together with the sentence "The name that I have entered is: "), I enter the name Gavin, and what I get is "The name that I have entered is: Gavin", and this sentence appears ABOVE the textbox. It seems that the position is default, and there is nothing that can be done. Am I right? Is there ANY way to reposition my sentence so it appears BELOW the text box. Also, is there any way to make my textbox disappear once I have entered my name and clicked on SUBMIT?
<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
echo "Hello, {$_POST["name"]}, and welcome.";
}
?>
<html>
<head>
<title>Image</title>
<style>
p.pos_fixed {
position: fixed;
top: 30px;
right: 50px;
color: black;
}
h4 {
text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
<b>Brown University:</b>
<br><br><br>
<b>Department of Physics:</b>
</p>
<ul>
<li>question1</li>
<li>question2</li>
</ul>
The name that I have entered is:
<form action="brownuniversity.php" method="post">
If you want to take part in this star-gazing project, enter your name:
<input type="text" name="name">
<input type="submit">
</form>
at the TOP LEFT of my web page
Because that's where you're putting it. Take a look:
...
if(!empty($_POST['name'])) {
echo "Hello, {$_POST["name"]}, and welcome.";
}
echo <<<_END
<html>
...
You're outputting the sentence before the HTML even begins. So of course it's going to be... before the HTML.
If you want it in a specific location of the page, output it at that location. For example:
...
<?php
if(!empty($_POST['name'])) {
?>
The name that I have entered is: <?php echo $_POST["name"]; ?>
<?php
}
?>
<form action="brownuniversity.php" method="post">
...
For a starter, tidy up the code.
This hopefully works.
<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
echo "Hello, {$_POST["name"]}, and welcome.";
}
?>
<html>
<head>
<title>Image</title>
<style>
p.pos_fixed {
position: fixed;
top: 30px;
right: 50px;
color: black;
}
h4 {
text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
<b>Brown University:</b>
<br><br><br>
<b>Department of Physics:</b>
</p>
<ul>
<li>question1</li>
<li>question2</li>
</ul>
The name that I have entered is:
<?php
//brownuniversity.php
if (isset($_POST['name'])) {
$_POST["name"];
}
?>
<form action="brownuniversity.php" method="post">
If you want to take part in this star-gazing project, enter your name:
<input type="text" name="name">
<input type="submit">
</form>
Beginner to PHP, so I am pretty sure this is a stupid question...but, was hoping someone can help me out.
I have a html/php form, which basically dynamically pulls in values from a DB for a dropdown.
//HTML/PHP (original page)
<div style="position: relative; float: left; width:236px; margin-right: 20px;">
<div id="variablebox" style="position: relative; float: left; width:215px; border: solid #0096D6; border-width: 1px; padding: 10px;">
<H2>Step 2: Select Variable Type</H2>
<form id="var" enctype="multipart/form-data">
<span style="float: left; margin-top:8px;">
<label class="fieldlabel"><span>Variable Type:</span></label></br>
<select id="variabletype" name="variabletype" class="selectfieldshadow">
<option value="">Select</option>
<?php
$list=mysqli_query($con, 'SELECT * FROM valuelist');
while($row_list=mysqli_fetch_array($list)){
?>
<option value="<?php echo $row_list['valuelistid']; ?>">
<?php echo $row_list['valuename']; ?>
</option>
<?php
}
?>
</select>
</span>
When this form is submitted, it basically submits to PHP file via AJAX and then return the same form to the screen within the same DIV.
//PHP Page
echo "<H2>Step 2: Select Variable Type</H2>";
echo "<form id='var' enctype='multipart/form-data'>";
echo "<span style='float: left; margin-top:8px;'>";
echo "<label class='fieldlabel'><span>Variable Type:</span></label></br>";
echo "<select id='variabletype' name='variabletype' class='selectfieldshadow'>";
echo "<option value=''>Select</option>";
echo "<?php";
echo "$list=mysqli_query($con, 'SELECT * FROM valuelist');";
echo "while($row_list=mysqli_fetch_array($list)){";
echo "?>";
echo "<option value="<?php echo $row_list['valuelistid']; ?>">";
echo "<?php echo $row_list['valuename']; ?>";
echo "</select>";
echo "</span>";
echo "<span style='position: relative; float: left; display: inline-block; margin-top: 7px; font: 12px Lucida Grande,Helvetica,Arial,Verdana,sans-serif; padding-right: 60px;'>";
echo "<p>Add Value Control Screenshot:</p>";
echo "<input id='controlimage' type='file' name='controlimage'>";
echo "</span>";
I keep getting errors with my output...T_Variable this and Exception that...my question is, am I going about doing this correctly? I mean, looking at my PHP file that will return content back to the original page, do I have to echo php tags so they work on the original page when returned? ie. echo "<?php" etc..
Any assistance would be much appreciated!
echo is used to output content. As it's currently written, you're just trying to display the PHP code. To execute it, you'll have to restructure your code as follows:
<!-- some HTML code -->
<?php
// display stuff
?>
<!-- continue with HTML -->
Well first of all, PHP is all rendered server-side. So that means returning PHP in an AJAX response doesn't make sense. It won't render on the client side.
Second of all, those echos look crazy too. There are several different ways to output large text like that. Personally, I like to just close the PHP tag and write it. So your second file could look like this instead:
// end all PHP for now
?>
<H2>Step 2: Select Variable Type</H2>
<form id='var' enctype='multipart/form-data'>
<span style='float: left; margin-top:8px;'>
...
<input id='controlimage' type='file' name='controlimage'>
</span>
<?php
// continue writing PHP here
Send PHP is a nonsens cause PHP is a Server side language (run on server and not on the client, the browser).
Why don't you run your PHP code in this script and return the result. (Just display it)
But, please, make us proud of our favorite language and its beginners:
Use mysqli_fetch_assoc() instead of mysqli_fetch_array()
Use only one echo to do a multiline display, PHP natively supports it.
Indent your code, you will really like how it's more readable.
Use jQuery, its AJAX methods and autocomplete widget. Somebody did the job for you. ;-)