I have a long text string that needs to be displayed after being fetched from database. I'm able to display it on the screen, however when the string is too long, the complete string is not being displayed. Here is my code:
echo '<td>'.'<input type = "text" class="form-control" disabled = "disabled" id ="fieldText" name = "fieldText['.$row["ID"].']" value = "'.$row["fieldText"].'">'."</td>";
Not sure what changes need to be made in order to display the complete string. Can someone help please.
Try use textarea. replace you input field with a textarea tag with the same name
echo '<td>' . ' <textarea class="form-control"
name = "fieldText['.$row["ID"].']"
value = "'.$row["fieldText"].'"
cols="40" rows="4" ></textarea>' . "</td>";
Related
If it has a single quote in it, any string that I try to enter into my HTML input box is truncated in the input box once it is submitted. Its POST value comes thru unchanged, but the string shows as truncated in the input box, whether I use htmlspecialchars() or not. A noobie question, no doubt, but I've tried hard to figure it out and run out of ideas. Thanks for any help.
<!DOCTYPE html>
<body><title> Self-inserting input_box_SO.php </title>
<?php
// POST form initiation.
ECHO "<form action='input_box_SO.php' method='post'>";
// GET POSTed value and escape it for HTML use
$Caption_htmlspecialchars=$_POST['Caption_htmlspecialchars'];
$Caption_htmlspecialchars=htmlspecialchars($Caption_htmlspecialchars);
ECHO "The echo of the variable <em> \$Caption_htmlspecialchars </em> looks like this:<br>";
ECHO "<b> $Caption_htmlspecialchars </b><br>";
ECHO "But in the input box, \$Caption_htmlspecialchars is truncated by a single quote: <br>";
// ETA: Bad old line that caused the problem, now commented:
// ECHO "<input type='text' name='Caption_htmlspecialchars' size=100 value='$Caption_htmlspecialchars' maxlength = 100 required /><br><br>";
// ETA: Newly added line that fixes the problem:
echo '<input type="text" name="Caption_htmlspecialchars" size=100 value="'.$Caption_htmlspecialchars.'" maxlength = 100 required /><br><br>';
// SUBMIT button. Submits back to the same page: input_box.php
echo "<b><input type='Submit' name='submit' value='Submit'/></b></br></br>";
?>
</body></html>
Here is what Inspect Elements > Elements shows for the input element:
input_box_SO.php
The echo of the variable $Caption_htmlspecialchars looks like this: test with special chars. & " < > and a single quote ('), which causes truncation in the input box. But in the input box, $Caption_htmlspecialchars is truncated by a single quote: and a single quote (" ),="" which="" causes="" truncation="" in="" the="" input="" box.="" '="" maxlength="100" required="">
With the Source looking like this: value='test with special chars. & " < > and a single quote ('), which causes truncation in the input box. '
You need to change your sequence of single quotes nad double quotes to display string. change your echo <input as below
echo '<input type="text" name="Caption_htmlspecialchars" size=100 value="'.$Caption_htmlspecialchars.'" maxlength = 100 required /><br><br>';
Try to use the addslashes and do it like
$Caption_htmlspecialchars = addslashes($Caption_htmlspecialchars);
I am currently writing some search engine, where this page is retrieving some _GET variables from a previous page. This is working as intended.
Now I am using those variables as default value in a POST form. However, for some reason, only the first word for each of them is showing up. The form code is as follows:
<form action = "insert.php" method = 'POST'>
<Place name <input type="text" name="name" size = "30" value= <?php echo $_GET['name']; ?> />
Note that when echoing $_GET['name'] anywhere else in the page, everything is fine. Multiple words show up as expected, but when I use it as a text box default value, only the first word shows up on the textbox.
At first, I thought it had something to do with the way those $_GET variables are sent in the URL so I tried this:
$fullname = array();
$fullname = explode("%20", $_GET['name']);
$aaa = implode (' ',$fullname);
...
Place name <input type="text" name="name" size = "30" value= <?php echo $aaa; ?> />
but the result is still the same. If I echo it anywhere else in the page I get the full string, but if it's inside the form only the first word shows up.
What am I missing here?
The value attribute of the input tag needs to be in quotes:
<input type="text" name="name" size = "30" value="<?php echo $_GET['name']; ?>" />"
Otherwise, if $_GET['name'] contains spaces you'll end up with something like: value=John Smith. That will be understood as value=John with an invalid Smith attribute floating around.
Also, consider sanitizing $_GET['name'] with htmlspecialchars. Consider what would happen if $_GET['name'] was "/><script>alert(0)</script><. You'd end up embedding user-controlled code on your website, resulting in a reflected XSS.
I'm trying to get the value from two input fields and pass them as the name in a form.
In my code, I am hardcoding the value of the price range in for testing purposes.
echo 'PRICE RANGE:';
echo 'Low: <input type="text" name="t[pr_100000]" value="" maxlength="25" /> High: <input type="text" name="t[ph_10000000]" value="" maxlength="25" />';
echo 'STATUS:';
$termsStatus = get_terms( 'Status', array(
'hide_empty' => 0
) );
echo '<ul>';
foreach ($termsStatus as $term_st) {
$termsStatus = $term_st->name . 'PropertyFilter';
echo '<li><label><input type="checkbox" name="t[st_' . $term_st->name . ']" value="st_">' .$term_st->name. '</label></li>';
}
echo '</ul>';
Here is the code on another page that the search parameters are sent to:
// GETS THE VARIABLE FROM THE SEARCH WIDGET
$array_terms_test = array_keys( $_GET['t'] );
Any suggetions? Thanks in advance!
Judging by your comment, it seems like you are having trouble passing the input fields to the second snippit of code (via a submit button or javascript). You need to surround the input fields with a form tag and submit the form. If you want to use $_GET simply assign action='get' on the form. If for some reason this doesn't work for you, you can use javascript to pull the values from the fields and create a url var which you use to redirect (window.location = url).
Sorry if I didn't understand your question.
I created a text box as follows-
<textarea name ="textbox" rows="20" cols="50" id ="textbox" style="background-color: #000000; font-size:14.5px; font-family:arial; color:#FFFFFF;"> </textarea>';
In the PHP script,I am trying to get the contents of a file and then trying to populate the value field of the textbox as follows :
echo '<script> document.getElementById("textbox").value = "'.$final1.'";</script>';
where $final1 = file_get_contents(FILENAME);
I see that there is nothing populated in the value field and neither do i see any output when I try to echo this variable. I tried giving a variable say $test = "ABCD"; and populating this variable and it worked.
I know this has something to do with HTML special characters because my file has lot of special characters but I am not able to find a solution.
Kindly please help. Thanks!
If you problem is related to the file you load having special characters in to that html/javascript does not like try this
$final1 = htmlspecialchars( file_get_contents(FILENAME) );
echo '<script> document.getElementById("textbox").value = "'.$final1.'";</script>';
I have this code basis:
echo '<input required type = "text" name = "subject1" value="XXX" />';
However, I would like XXX to be a variable, I have searched this online, but all the things that one of the discussions says is to do this:
value=\"$firstName\"
or
value='$firstName'
I have tried both of these, but they don't work, and I was hoping that someone could help me with this problem, basically, what I want is to be able to asign the value of a text edit to a variable in php, but when the text edit itself, is embedded in an echo, nothing seems to work.
Thanks
Concatenation is a pretty easy way to go about this:
echo '<input required type = "text" name = "subject1" value="' . $foo . '" />'
edit: Those spaces around the concatenation .'s (. $foo .) aren't required - I just add them fore readability.
I think the problem is you are using single quotes, so variables are not rendered automatically... you can concat with . like this:
echo 'some text' . $variable . 'some more text';
echo '<input required type="text" name = "subject1 value="<?php echo $value; ?>" />';
acutally you don't need the php echo .... stuff.... /* brain not engaged */