user4640949
user4640949

Reputation:

How to clear the URL_GET after clicking hyperlink

When I press a hyperlink

<.a href="template_edit.php?templateId=...&bbId=...&editReq=...">  
  <.img src="...">  
<./a>

It will refresh the page cuz I was already on 'template_edit.php?templateId=...'
But when the refresh is done and the query has been updated succesfull I want that the $_GET['bbId'] and the $_GET['editReq'] will get deleted without refreshing the page again.

I hope you guys can help me with this.
If you need more information to help me, say it please.

Thankz.

[EDIT-1]
Steps:
1: I have the hyperlink that is filled with a link to a page with 3 GET's in it.

2: Then it refresh the page cuz it is already on that page en the URL GET's are filled in.

3: Then when the query that will update things in the DB is done succesfully it needs to delete 2 GET's of the 3 GET's without refresh the page!

[EDIT-2]
Some more information maybe handy.
The code what i have till now is this.

//This is the update query
if (!empty($_GET['editReq'])) {
  mysql_query("
    UPDATE formbbformtemplate
    SET formRequired = '".$_GET['editReq']."'
    WHERE formTemplateId = ".$_GET['templateId']."
    AND formBuildingBlockId = ".$_GET['bbId']."
  ") or die(__LINE__.": ".mysql_error());
}

//The hyperlink / image button.
<a href="template_edit.php?templateId=<?=$templateId?>&bbId=<?=$vragen['formBuildingBlockId']?>&editReq=off">
  <img style="opacity: .25;" src="<?=IMG?>/cross.png" title="Niet Verplicht!">
</a>

//Below here there needs to come the SCRIPT
<script>
  //script
</script>

Upvotes: 1

Views: 547

Answers (2)

Raheel
Raheel

Reputation: 9024

You can do it via jquery on your template_edit.php like

$(document).ready(function(){
  var url = window.location.href;
  if(url.indexOf('&') !== -1) //This will check if the url contains more than 1 GET.
  {
   url = url.slice( 0, url.indexOf('&') ); // This will keep the first GET 
   window.location.href = url;
  }
});

Upvotes: 4

jyrkim
jyrkim

Reputation: 2869

Can you for example check in your php code if the page request is initial or a refresh one (following your hyperlink click). Something like below:

//test for refresh 
if (isset($_GET['bbId']) && isset($_GET['editReq']) ) {
    //create your anchor tag here without 'bbId' and 'editReq'
  <a href="template_edit.php?templateId=<?=$templateId?>">
  <img style="opacity: .25;" src="<?=IMG?>/cross.png" title="Niet Verplicht!">
</a>

} // else initial page request
else {      
  //create your anchor tag here as usual
      //The hyperlink / image button.
<a href="template_edit.php?templateId=<?=$templateId?>&bbId=<?=$vragen['formBuildingBlockId']?>&editReq=off">
  <img style="opacity: .25;" src="<?=IMG?>/cross.png" title="Niet Verplicht!">
</a>
}

I haven't tested the above but it could work :-)

Upvotes: 2

Related Questions