When link clicked add link value into url after another link has been clicked

394 views Asked by At

When clicking link-1 or link-2 a modal will come up (they use the same modal) with link-a and link-b.

enter image description here

enter image description here

When link-a is clicked I need it to be <a herf="/link-1/link-a/">link-a</a> So when that is clicked the url path will be as below

www.example.co.uk/link-1/link-a/

This is what I have so far;

<?php 
$current_url = $_SERVER['REQUEST_URI'];
$add = 'link-1'; 
$final = $add;
?>

<a href="/<?php echo $final;?>/link-a">link-a</a>
2

There are 2 answers

1
Amit Sharma On

I think you need to do it like this

<?php 
 $current_url = $_SERVER['REQUEST_URI'];
 $add = 'link-1'; 
 $final = $current_url.'/'.$add;
?>

<a href="<?php echo $final;?>/link-a">link-a</a>
0
Pat On

Can you just pass the link-1 / link-2 url as a parameter for your modal?

Something like this:

//button for modal
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Modal" data-url="www.example.co.uk/link-1">Link 1</button>

//passing url to modal
 var url = button.data('url')
 var modal = $(this)
 modal.find('.modal-body').html("<a href='" + url + "'/link-a' >Link-a</a>")

modal doc