Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Database field with a href link, how to display in a view ?

Hello,

I work on an app (it's not a Laravel app, just PHP / JS) that has been developed by another dev.

In the database there is a table with a description field. Sometimes the users do some copy / paste with a link with parameters.

https://mydomain.com/page?param=4&otherparam=othervalue&...

The getter retrieves the description with nl2br($this->description) (the description is typed by the user in a textarea).

All messages without any link inside it display correctly in the view. But if there is a link, only the start if the link is displayed.

https://mydomain.com/page?param=4

And the &otherparam=othervalue&... doesn't appear in the source code of the view, so that all what is after is inside a link which is not closed with </a>. That means that all the further tags, datas, ... are in this unclosed link.

I want to change the minimum required in the existing code, and I have 2 ideas :

1 - I could just handle the description in the getter in order to display correctly the link when it has to be displayed in the view

2 - I could also try to update the save script of the description in the database taking into account that it could contain a link

In both cases I'm lost because generally I use some plugin like tinyMCE, but in this app, even if is would be possible to add a wysiwyg, I don't think it's a good idea for the moment.

Furthermore there is around 200 lines in the table with this problem, so I have to solve how to display the existing datas, instead it will be necessary to update these lines in the database to avoid the bug.

If you have any idea to help me, thanks in advance ;).

Vincent

0 likes
9 replies
Snapey's avatar

is the html tag also in the description or is the description free from html?

It sounds like the description is being passed through some filter that strips html entities?

Have you looked at the actual code that gets emmited to the page? What does the link look like there?

1 like
vincent15000's avatar

@Snapey The <htm> tag is not in the description (only the <a> tag).

I don't really understand what does this code, but it could be the manipulation of the content of the textarea before sending it to the controller via AJAX.

// It's inside a loop

var id_reponse = $(this).find('input[name=id-reponse]').val();
var description_reponse = $(this).find('textarea[name=text-reponse]').val();

if(i > 0){
	reponses = reponses + "&";
}

reponses = reponses +  "reponses[" + id_reponse + "]=" + description_reponse;
i = i + 1;

The code that emits the page view sends this link < href="https://mydomain.com/page?param=4, you can see that the end of the link is not displayed and the link is not closed.

Snapey's avatar
Snapey
Best Answer
Level 122

@vincent15000 but is the end of the link in the database. If so, forget about the creation part (I assume thats what the ajax is)

What does the html look like in the page (view source) when you try and show the link?

1 like
vincent15000's avatar

@Snapey The link is correctly saved in the database and it is complete and the <a> is closed.

Here is an example of the content of the description field in the database.

Une fiche (<a href="index.php?param=value&otherparam=othervalue&anotherparam=anothervalue&id=jksdfhgkjsdhflgkjhdsflgkjdsfhg">Réf 18-5555-1245</a>) est en cours.

Sorry I don't show the real params but it's only strings with only letters.

In the view the source code in the browser looks like this.

<div>
	// some content
	Une fiche (
	<a href="index.php?param=value <div class="myclass">
		// some text content
	</a>
</div>

Well I just see that the a tag is closed, but why is a div written inside the <a ... <div>... tag ?

And the > is not present to terminate the a tag.

And the div tag seems to be not closed.

But when I look at the code in the view file, all tags are correctly written.

vincent15000's avatar

@Snapey I have copied the link from the view.

https://mydomain.com/index.php?param=value%3Cdiv%20class=
Snapey's avatar

Well I just see that the a tag is closed, but why is a div written inside the <a ... ... tag ?

@vincent15000 Are you showing the actual page source or inspecting it in developer tools?

1 like
vincent15000's avatar

@Snapey Yes ... I have new informations ...

When retrieving the description field from the database, I have noticed that it is incomplete, cut just at the place where is the first & in the link.

Could it be a problem with some database configuration ?

vincent15000's avatar

@Sinnbeck I know a part of the problem now ... I have new informations again ... some descriptions are saved with the complete link and other descriptions are saved with cut links.

It's not a display problem, but a problem while saving / updating the model.

So I search now where the model is saved and/or updated.

Please or to participate in this conversation.