How to insert an active link in an input text box?

Can I insert an active link in an input text box?

I tried using the tag <a>inside the html value, but it did not work.

<?php $email = "<a href=\"example@link.com\">example@link.com </a>"; ?>   

<input type="text" id="email" name="email" value="<?php echo $email; ?>">  

It returns text without a hyperlink value.

+4
source share
3 answers

Here are a couple of mistakes ...

  • You do not avoid your quotes. Therefore, PHP is not valid.
  • You are trying to put HTML inside an attribute, which is also invalid.

The only alternative I could see here is an HTML c element contenteditable="true". This makes it so that the element (per say a <div>) can modify its contents.

<?php $email = "<a href=\"example@link.com\">example@link.com </a>"; ?>   
<div id="fake-email" contenteditable="true"><?php echo $email; ?></div>

, .

Edit:

, :

document.getElementById("form").onsubmit = function(){
    document.getElementById("email").value =  
    document.getElementById("fake-email").innerText || document.getElementById("fake-email").textContent;
}

:

<form action="..." method="..." id="form">
   <div id="fake-email" contenteditable="true"></div>
   <input type="hidden" id="email" name="email" />
</form>
+5

, . . , .

WYSIWYG. .

TinyMCE

CKEditor

+2

, php.

<?php $email = "<a href=\"example@link.com\">example@link.com </a>"; ?> 

, .

:

 <?php $email = '<a href="example@link.com">example@link.com </a>'; ?> 

, . \

, .

0
source

Source: https://habr.com/ru/post/1568566/


All Articles