Prevent quotation in window.open in PHP - php

I'm having a problem with my script. The file wont open if the filename has single quote.
Is there a way to prevent single quote in window.open?
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print($contRow['cont_file']); ?>','<?php print($contRow['cont_file']); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
here's the output
7TATTOOED ON MY MIND CHORDS (ver 2) by D'Sound # Ultimate-Guitar
Sample Output 1.
Sample Output 2.

You should encode your filename I think:
urlencode($contRow['cont_file'])

I tried this code:
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print(addslashes($contRow['cont_file'])); ?>','<?php print(addslashes($contRow['cont_file'])); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
and It works like a charm. thanks anyway. Credits to the one who deleted he's post but it works.

Related

Text has space to the right

I have the following code:
<div class="brm-item-name">204 Banane, Milch & Erdbeeren <button type="button" class="btn btn-info btn-xs" id="pop" data-toggle="modal" data-target="#myModal"></button></div>
"204 Banane, Milch & Erdbeeren " is pulling from database but text does not have a space in the database. The space here is giving me trouble when writing css. Do you have any suggestions on this?
You can remove it using jQuery trim().
jQuery(document).ready(function($) {
$('.brm-item-name').trim();
})

Open modal when redirected only

Before, I had a view called "book-edit/[ID]" to edit a book but now I added the form to edit the book in the book details page. I have a button to edit in the list of books page and I want it to go to the book page and open de edit modal on click. This is what I have rn:
View: Books (datatable list with this buttons for each):
<a href="<?php setURL(); ?>./book/<?php echo $autor->fields["id"]; ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="View Book">
<i class="fas fa-eye"></i>
</a>
<a href="<?php setURL(); ?>./copy-add/<?php echo $autor->fields["id"]; ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Add Copy">
<i class="fas fa-plus"></i>
</a>
<a href="<?php setURL(); ?>./book-edit/<?php echo $autor->fields["id"]; ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Edit Book">
<i class="fas fa-edit"></i>
</a>
View: Book/[ID] (I have modals with id "#editBookModal" and "#addCopyModal")
When you click on the books list to edit the book or add the copy, I want it to go to book/[ID] and automatically open the intended modal. But only when buttons clicked, if you go to Book/[ID] to view the book, it shouldn't open the modals automatically. That's why I can't just open it with jquery in the book/[ID] page...
Any idea of how I can do this?
Thanks!
One approach would be add hashes to the url in the links like:
....
Then on the other page check the url hash and if it matches a modal then open that modal
const modalHashes = {
'#edit-book':'#editBookModal',
'#copy-book' : '#addCopyModal'
}
let hash = window.location.hash;
// inside document.ready and after modal script has loaded
if(hash && modalHashes[hash]){
const modalSelector = modalHashes[hash];
$(modalSelector).yourModalShowMethod()
}
You could even remove the hash when the modal gets closed so if user refreshes the page it won't pop up again
// in modal close event handler
window.location.hash =''

href contains php variable in it not opening correct location

I have the following <td> tag with <a> tag in it that contains a php variable in href. I only can browse upto uploads folder. Does anyone know why? It supposed to browse until uploads\$_POST['searchInput'] . But it is not doing that.
<td class="viewEditTd"><button class = "btn btn-info viewEditButton"><a href="file://///172.xx.xx.xxx\TEMP\xxx\uploads\"<?php echo $_POST['searchInput']; ?>"\" target="_blank"><span class="
glyphicon glyphicon-folder-open" aria-hidden="true"></span> View File</a></button></td>
I am able to solve the issue with the help of Stack overflow forum member. This is how it solved. My issue was as below
<td class="viewEditTd"><button class = "btn btn-info viewEditButton"><a href="file://///172.xx.xx.xxx\TEMP\xxx\uploads\"<?php echo $_POST['searchInput']; ?>"\" target="_blank"><span class="
glyphicon glyphicon-folder-open" aria-hidden="true"></span> View File</a></button></td>
It was solved by removing the two double quotes around the php tags. Working answer is
<td class="viewEditTd"><button class = "btn btn-info viewEditButton"><a href="file://///172.xx.xx.xxx\TEMP\xxx\uploads\<?php echo $_POST['searchInput']; ?>" target="_blank"><span class="
glyphicon glyphicon-folder-open" aria-hidden="true"></span> View File</a></button></td>

How to use bootstrap "modal box" instead of "<a> tag and new page"?

I can show details data in a new page using details.php using anchor tag like bellow :
<a class="btn btn-info" href="details.php?view_id=<?php echo $row['studentID']; ?>" title="click for Details" onclick="details.php"><span class="glyphicon glyphicon-eye-open"></span> Show Details</a>
Now I am trying to learn it to show using bootstrap modal box like code bellow:
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Details</button>
I have put the code of "details.php" in #myModel section and how I can show details data using dynamic ID - comes from view_id= for the code I am trying?
Please help me to understand my mistake. Thank you.

How can I get a URL for a controller action?

I have a link that looks like this:
<a class="btn btn-primary edit"
href="Personas/details/<?php echo $persona['Persona']['id']; ?>"
data-original-title="Editar">
<i class="icon-pencil icon-white"></i>
</a>
As you can see I'm manually writing in the controller and action for the link. Is there some way to make this not as brittle?
Something like:
<a href="Url.Action("Personas", "Details", array('id', 1);" >Asdf</a>
Use: Html->url, does exactly what you want.

Categories