I have a form which i am using to update adds on my site, I am filling input value with existing adds but there is a problem in form it is showing adds images instead of text value.
I need to update adds link by replacing the link value in input field.
Input field has value as
<input name="addtop" type="text" value="<a href="http://www.xxyy.com/4g...." target="_blank" <img src="http://www.xxyy.com/h4...."/></a>" />
when i try to load page it shows image in input field instead of text as:
<a href="http://www.xxyy.com/4g...." target="_blank" <img src="http://www.xxyy.com/h4...."/> ></a>`
Please see how can I make input to show links in value instead of images.
You should use htmlspecialchars for whatever sets the value= of those <input type="text"> boxes.
It will take image tags and HTML and render them as HTML entities that will safely be place in that text box.
Then when you want to process the contents of that for, just use html_entity_decode to decode the HTML entities.
UPDATE: Your first attempt to fix this—shown in the comments—is this:
<input name="addtop" type="text" value="htmlspecialchars(<?php echo $addtop?>)" />
That is just incorrect. htmlspecialchars is a PHP function. So you need to put it in the <?php … ?> area. It should be:
<input name="addtop" type="text" value="<?php echo htmlspecialchars($addtop)?>" />
Related
I have these inputs that take the values of a from a in my table when I click on a row. I want to make it so that the user cannot change the input themselves but want to bring values into them when a user clicks a table row. I will be passing these inputs in as a form. I know that when the input is like this:
that it will not be updated. Is there any other way to do it with an input. Is there a different type of tag I can use that can be passed through a form?
Rather than a read-only <input>, I'd go with a combination of a display element and a hidden form element. Something like:
<div id="my-display">This is a value</div>
<input id="my-input" name="my-input" type="hidden" />
And in the code update both:
$('#my-display').text(yourValue);
$('#my-input').val(yourValue);
You can style the display to the user however you like and don't have to worry about whether or not it "de-activates" the form input.
If you really want it to be an inactive input, you can use the same approach:
<input class="my-input" type="text" disabled />
<input class="my-input" type="hidden" name="my-input" />
Which may even save you a line of code here, since both can now use .val():
$('.my-input').val(yourValue);
Try disabled keyword as here
<div id="my-display">This is a value</div>
<input id="my-input" name="my-input" type="text" disabled/>
You can change the value by javascript as below:
document.querySelector('#my-input').value = 'the value you want to enter by javascript';
How can I show image name through the browse field. Sorry that, I am new in PHP.
I use this code, but it's not working
<input
id="photo"
type="file"
value="<?php echo $results['image'];?>"
class="form-control"
name="image" />
You can not show a image on a input field.
What you can do is:
<img src="allYourDomainURL/<?php echo $results['image'];?>" />
That would effectively show a real image to the user.
I'm guessing what you want to do is to show inside the input type file the image you uploaded once the form is submitted. I am afraid that is not possible.
What you can do is save the image on a folder inside your project, save that into a variable, for example $image. Then show it inside your form, you can even create a link so that when they click on it the image will appear on a different tab.
Is there a way to have javascript create php code, to be executed when it runs on the php page? I'm trying to set the value of an input to , where div_id is a js variable, and inputs is a 2D associative array.
The problem is that it literally sets the value to "" instead of the value of the floor_type field. Everything else seems to work.
inputs_div.innerHTML += `<div id="`+div_id+`" class="dynamic_div">
<ul class="dynamic_ul">
<li><input type="text" onblur="$('.save').click();" placeholder="Flooring Type: Wood Floor, Tile, etc." name="inputs[`+div_id+`][floor_type]" maxlength="255" value="<?php echo $_SESSION['inputs']['`+div_id+`']['floor_type']; ?>"></li>
</ul>
</div>
I'm creating some html inputs dynamically with javascript, but I'm looking for a way to prevent them from getting cleared if the page is refreshed. Maybe there is a simpler way to make the inputs stay there?
My idea was to use ajax to run some php code from the onblur event of each input element, which saves the inputs[][] array into the session, so it doesn't get lost when refreshing the page.
Use a hidden field to store $_SESSION[] value and then on document ready get the value of hidden field and set to the javascript variable.
<input type="hidden" id="hdn" value="<? php echo $_SESSION['inputs'] ?>" />
$(document).ready(function()
{ var session_value = $('#hdn').attr('value'); // now use session_value variable when set the innerhtml of inputs_div });
I'm trying to figure out how to pass the URL of a current page via a hidden field so that I can redirect back to that page after the form's input has been handled. I've tried using javascript:location.href, however it looks as though it'll pass that as a literal string.
<input type="url" id="location" name="location" value="javascript:location.href" hidden />
When viewing the page source, I can see that the value of this input box is "javascript:location.href" rather than the page's URL. Any ideas here? Thanks in advance!
You can access the element in Javascript and change the value there
document.getElementById('location').value = location.href;
Example:
http://jsfiddle.net/6zxD5/
I don't think it works that way. You could just use the onload callback to insert it when the page is completely loaded:
<body onload="document.getElementById('location').value = document.location.href">
If your document containing the form is already a PHP file , you can do
$yourPath = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
And in your html you would do
echo '<input type="url" id="location" name="location" value="'.$yourPath.'" hidden />';
You can use JavaScript to set the value of the hidden field:
document.getElementById('location').value = window.location.href;
Example:
https://jsfiddle.net/moogs/mhjh0je3/
Since you also tagged PHP, here's the PHP version:
<input type="hidden" id="location" name="location" value="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" />
I have an HTML form with many fields, including a text field, that is,
<input name="my_field" type="text"></input>
Now, this text field is being changed by tons of JavaScript, jQuery and CSS code. The result of all this interaction is that when the form is submitted, this particular text field simply gets ignored (it is like that field was not there). I am not saying it get submitted with empy text, it simply doesn't appear in the list of fields submitted...
Because there are tons of code affecting this particular text field, I don't know what is causing this weird behavior. So I was wondering if someone could tell me what kind of HTML attribute (or JavaScript code, or jQuery code, or ...) could result in a text field being ignored.
At the end of all this interaction, I get the following HTML code (retrieved using the "Inspect Element" from Chrome):
<input id="id_my_field" maxlength="200" name="my_field" type="text" class="tt-query" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: transparent;" data-original-title="" title=""></input>
You should add a name attribute to the input:
<input type="text" name="myinput" />
Add the name attribute, like this:
<input name="myField" type="text"></input>