Auto Filled textbox in php - php

I am a beginner.
I created a simple generator of pictures and I would like that when he was generate code in the text box and not as plain text.
Please help.
So it should look like: http://i.stack.imgur.com/cXT7X.jpg

I suppose you are doing something like
echo $code;
to show your code; if this is the case so you only have to do it like this :
echo '<input type="text" name="my_code" value="' . $code . '">';
or
echo '<textarea name="my_code">' . $code . '</textarea>';
That's it

Use basic HTML FORM elements with readonly attribute.
<textarea readonly><?php echo $code; ?></textarea>

Just keep in mind that PHP generates HTML that the browser parses...
<input type="text" name="url" value="<?php echo htmlspeciachars($url,ENT_QUOTES); ?>">
its important to use ENT_QUOTES or some other kind of data filter to avoid XSS.

I didn't understand what i am saying but if you want to set the text inside the text input than you should use value element in input tag. For example your code should look like this :-
<input type="text" value="<?php echo $yourvalue;?>" />
Hope this works for you.

Related

PHP - How to pass variable in a text filed with double quote

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'] ?>" />

PHP inside echo in a function?

I have this part of the code of a plugin, which continues and has much php before it, fluidly without the ?> till the end of all the code.
function fivu_thumbnail_meta_box_html() {
echo '<label for="featured_image_url">';
_e("URL of featured image", 'fivu_textdomain' );
echo '</label> ';
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="" size="30" />';
}
What i need is to change the input value="" (5th line) to this:
value="<?php get_post_custom_values("Poster"); ?>"
But as i am inside of an echo, the php is not interpreted as php but as normal text.
¿What can i do to make the php inside of the echo not to be interpeted as normal text?
EDIT: Ok, i am using
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' . get_post_custom_values("Poster") . '" size="30" />';
But i forgot, lol, i need to echo the value. So how do i add: echo $values[0]; ?
I don't like HTML in echo.
So Try :-
function fivu_thumbnail_meta_box_html() {
?>
<label for="featured_image_url">
<?php
_e("URL of featured image", 'fivu_textdomain' );
?>
</label>
<input type="text" id="featured_image_url" name="featured_image_url" value="<?php echo get_post_custom_values("Poster"); ?>" size="30" />
<?php
}
You don't need <?php again as you're already inside a PHP control. You simply need to concatenate your string with the get_post_custom_values function's return value, like so:
echo '<input ... value="'.get_post_custom_values("Poster").'" ... />';
So we have string + function's return value + string, three components which together contribute to the output of the input field HTML.
Use the string concatenation operator, .:
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' . get_post_custom_values("Poster") . '" size="30" />';

Quotes Within Quotes Issues

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=&quote;<?=$url;?>&quote;></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?

Using a PHP variable in a text input value = statement

I retrieve three pieces of information from the database, one integer, one string, and one date.
I echo them out to verify the variables contain the data.
When I then use the variables to populate three input boxes on the page, they do not populate correctly.
The following do not work:
id: <input type="text" name="idtest" value=$idtest>
Yes, the variable must be inside <?php var ?> for it to be visible.
So:
id: <input type="text" name="idtest" value=<?php $idtest ?> />
The field displays /.
When I escape the quotes,
id: <input type="text" name="idtest" value=\"<?php $idtest ?>\" />
the field then displays \"\".
With single quotes
id: <input type="text" name="idtest" value='<?php $idtest ?>' />
the field displays nothing or blank.
With single quotes escaped,
id: <input type="text" name="idtest" value=\'<?php $name ?>\' />
the field displays \'\'.
With a forward slash (I know that's not correct, but to eliminate it from the discussion),
id: <input type="text" name="idtest" value=/"<?php $name ?>/" />
the field displays /"/".
Double quotes, escape double quotes, escape double quotes on left side only, etc. do not work.
I can set an input box to a string. I have not tried using a session variable as I prefer to avoid do that.
What am I missing here?
Try something like this:
<input type="text" name="idtest" value="<?php echo htmlspecialchars($name); ?>" />
That is, the same as what thirtydot suggested, except preventing XSS attacks as well.
You could also use the <?= syntax (see the note), although that might not work on all servers. (It's enabled by a configuration option.)
You need, for example:
<input type="text" name="idtest" value="<?php echo $idtest; ?>" />
The echo function is what actually outputs the value of the variable.
Solution
You are missing an echo. Each time that you want to show the value of a variable to HTML you need to echo it.
<input type="text" name="idtest" value="<?php echo $idtest; ?>" >
Note: Depending on the value, your echo is the function you use to escape it like htmlspecialchars.
From the HTML point of view everything's been said, but to correct the PHP-side approach a little and taking thirtydot's and icktoofay's advice into account:
<?php echo '<input type="text" name="idtest" value="' . htmlspecialchars($idtest) . '">'; ?>
If you want to read any created function, this how we do it:
<input type="button" value="sports" onClick="window.open('<?php sports();?>', '_self');">
I have been doing PHP for my project, and I can say that the following code works for me. You should try it.
echo '<input type = "text" value = '.$idtest.'>';

How to echo $row["Text'] to a TextField

Using PHP I am able to query MySQL database and see the results echo using:
echo $row['Text'];
I would like the information to load into TextField myAnswer instead. Can anyone help?
Thanks
Like this
<input type="text" name="myAnswer" value="<?php echo htmlspecialchars($row['Text']) ?>" />
or
<textarea name="myAnswer" rows="6" cols="40"><?php echo htmlspecialchars($row['Text']) ?></textarea>
None of this seems to work for me. Upon looking further, I found the following:
http://www.daniweb.com/forums/thread252486.html -- You can not manipulate text fields like java or C# or as3 but you can echo or print out html tags and text. if you echo your text you will need to space or manipulate using css and html.
So I guess I can't get the results back from the query in a textbox using PHP and MySQL.
Thanks anyways
Going on assumption from your question, you might try something like:
<input type="textbox" value="<?php echo $row['Text']; ?>" />
If you're thinking about a textarea control it'd be like this:
<textarea><?php echo $row['Text']; ?></textarea>
<input type="text" name="myAnswer" value="<?php echo $row['Text']; ?>" />
<?php if ($row['Text']) {?>
<textarea><?php echo htmlspecialchars($row['Text']); ?></textarea>
<?php } ?>
if you are displaying in the same page, otherwise you can just leave out the if .. check.

Categories