How can I make multi line text input ?
My code outputs only the first word of any input
For example if I type in "Hello world" it will only print "Hello"
My goal is to display multi line text.
My current code is:
echo "<td><input type=text name=opis value=".$row['opis']." </td>";
I know is the correct tag , but i can't incorporate that into my code.
My code outputs only the first word of any input
For example if I type in "Hello world" it will only print "Hello"
Always wrap you attributes values in quotes. Suppose your $row['opis'] has value "some value here", so in rendered html it will be:
<td><input type=text name=opis value=some value here /></td>
So do you think browser will understand that "some value here" is data of value attribute and not a list of some other attributes?
So, use quotes with attributes' values, always:
echo '<td><input type="text" name="opis" value="' . $row['opis'] . '" /></td>';
As you can see I've changed quotes and also closed input tag ( />).
I am not sure about what you mean with a multi line text input, but in HTML that would be the textarea element.
You can use it and specify how much rows do you want it to show initially. It will normally be bigger than an input[type='text'].
Your code would be something like this:
echo '<td><textarea name="opis" rows="5">'.$row['opis'].'</textarea></td>';
Also, if you want to echo something that requires the use of " you can just do:
echo '<td class="test">'.$content.'</td>';
// or in its case the other way around
echo "<td class='test'>".$content."</td>";
Here's an example of the difference between the two elements:
<input type="text" value='Hello
World
!
I
Am
Here'>
<br><br>
<textarea rows="5">Hello
World
!
I
Am
Here</textarea>
Related
My query extract a data value from mysql table where are a double quote in the text.
Select mytitle from title_table
The result is: This is my title: "for school"
This value I want to put inside a text field, but is truncated in this position This is my title:
I print the title by this: <?php echo $rows['mytitle']; ?>
How to put the entire title in a text field?
Thanks
Print inside the value of the text field, example:
<input type="text" name="title" value="<?php echo $rows['mytitle']; ?>">
I have resolve this problem. Are easy, but in a first time make a wrong Google search.
I have resolve by this: htmlentities
I think you search for this
<?php
echo '<input type="text" value="' . $rows['mytitle'] . '">';
?>
or in plain HTML with
<input type="text" value="<?=$rows['mytitle'];?>">
Look to, for the second example you must have enabled short_tags in your php.ini or use
<input type="text" value="<?php echo $rows['mytitle'];?>">
try this
<input type="text" name="yourkey" value="<?php echo $rows['mytitle'] ?>" />
I'm making a query to the database and am showing the value in input type text as follows:
<input type='text' name='title' value="<?php echo $noticia->_title; ?>" />
What happens is that if the text coming from the database comes within "" the text does not appear because the " " of value. If I switch to '' have the same problem if the text coming from the database is inside ''. How can I solve this problem?
value="<?php echo htmlspecialchars($noticia->_title) ?>"
htmlspecialchars() will encode any HTML metacharcters in there that would otherwise break your form, e.g.
$title = 'Hello "Joe"';
<input ... value="Hello "Joe"" />
^---breaks the form
becomes
$title = htmlspecialchars('Hello "Joe"');
<input ... value="Hello "Joe"" />
Convert text to HTML with htmlspecialchars.
echo htmlspecialchars($noticia->_title);
I pulling text that is stored in my database using MySQL select so it is displayed in a form so it can be edited.
When the form is set to the string held in the database gets truncated at the first space so "Foo Bar" would be displayed as "Foo". This doesn't happen when using the tag.
I have made sure that the text field is big enough to hold the entire string and the number of charters isn't limited.
In the database the whole word is stored and no truncation is happening. I set the type to varchar(30) which is enough space to store the whole word. I have also tried changing the type to text and I still have the problem.
I can't seam to find a solution anywhere does anyone have an idea of why this may be happening?
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\" value=" . $row["title"] . ">"; ?>
You should provide a sample of the HTML produced from your php page. Most likely, your value string is not being quoted, e.g. your HTML form looks like:
<input type=text value=Foo Bar>
instead of
<input type=text value="Foo Bar">
This would produce exactly the effect you are seeing
UPDATE: Based on your example in the comment, you are indeed missing the quotes:
Old code with the problem (missing quotes around value attribute's value):
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=" . $row["title"] . ">"; ?>
Fixed code:
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=\"" . $row["title"] . "\">"; ?>
Note that you already had the name attribute correctly quoted, but value was not.
Without the relevant code, this is just a guess, but are you setting your form input value attributes without using quotes?
For example, are you doing this?
<input type="text" value=<? echo $value; ?> name="formInput" />
Instead of the correct syntax, which is this?
<input type="text" value="<? echo $value; ?>" name="formInput" />
i have the jquery accordion tabs. within those tabs, i have a hidden form which on click, is auto-filled with certain values displayed within that tab. It displays correctly within the accordion tab but when i pass those same variables as auto-fill values within the form, only the first word gets displayed if there is more than 1 word. the variable name that i have put as the value attribute of the text box is exactly the same so i don't know why this happens.
echo "<tr><p><td>".$allCourses[$i][0]."</td> - <td>".$allCourses[$i][1]."</td>
it gets displayed correctly here. however, here, only the first word appears:
<form action='editCourse.php' method='post'>
<p id='edit-course-d' class='edit-accordion-tab'><img src='images/edit.png' title='Edit Course'/></p>
<p id='edit-course-f' style='display: none'>
Course ID: <input type='text' name='edit-course-id' value =".$allCourses[$i][0]."><br />
Course Name: <input type='text' name='edit-course-name' value=".$allCourses[$i][1]."><br />
(all this is within the echo "" in php)
You have to put quotes around the content of your value-attribute, otherwise the "other words" are interpreted as HTML-attributes. So what is rendered to the browser looks like:
<input value=hello world>
The browser interprets this as an input element which has two attributes:
value="hello"
world=""
So you have to put quotes ' or double-quotes " around the value of the attribute. Like that:
echo "
<form action='editCourse.php' method='post'>
<p id='edit-course-d' class='edit-accordion-tab'><img src='images/edit.png' title='Edit Course'/></p>
<p id='edit-course-f' style='display: none'>
Course ID: <input type='text' name='edit-course-id' value='".htmlspecialchars($allCourses[$i][0])."'><br />
Course Name: <input type='text' name='edit-course-name' value='".htmlspecialchars($allCourses[$i][1])."'><br />";
I use htmlspecialchars to escape the quotes that might appear inside the values (this adds another layer of safety).
I'm trying to create a textbox that will be displayed on my website. When displayed, I'd like to show some data within the text box. Here is what I have
echo "<input type=\"text\" size=\"100\" value=\"\">";
All that shows up in the text box is <a href=
And then at the end of the text box, right after the text box I see ">
I know something must be syntactically off, just not sure what.
You must encode <, ", and > chars - they can't be embedded that way. Use:
echo '<input type="text" size="100" value="'.htmlspecialchars('').'">';
You may also use urlencode() function - see which suits you better.
One more tip - use single quotes when string contains HTML-like content. This will save you adding \" everywhere.
php_code ?>
<input type="text" size="100" value="<a href="e;<?=$url;?>"e;></a>\">
<?php
php_code
maybe this will work for you
Think of what the html would look like:
<input type="text" size="100" value="">
^
|
This is where the value attribute ends!
htmlspecialchars should solve it.
You have made some mistake. Your code will result in something like that (also visible in this jsfiddle):
<input type="text" size="100" value="">
Instead you can use something like that:
echo "<input type=\"text\" size=\"100\" value=\"<a href="$url"></a>\">";
or
echo '<input type="text" size="100" value="<a href="' . $url . '"></a>">';
to receive effect visible in this jsfiddle. Is it satisfying enough?