Jump to content

Adding PHP parameters to a URL when page loads


moshina786

Recommended Posts

Hi All.

 

I have been really struggling with this for a while! When a URL loads I wish to load with parameters entered & those parameters entered on a page but cannot get my head round it. Any help will be much appretiated...

 

So when a user navigates to www.test.com/page.php I wish to to actually pull back www.test.com/page.php?term=&submit=Go

 

Any help will be really really appretiated.

Link to comment
Share on other sites

Well you could use mod rewrite.

 

Or you could write the link with the variables in it (ie <a href="text.com/page.php?term=&submit=Go">link</a>) or use a header('Location: test.com/page.php?term=&submit=Go') to redirect (or javascript or meta tags if you'd prefer).

 

You could also use a form with a 'get' method that directs back to itself through the action part when a user submits it.

<form action="test.com/page.php" method="get">

Link to comment
Share on other sites

The menu has the full link within it so that's ok, but if a user navigates to www.test.com/page.php the parameters arent added. In more details, the parameters are for a form to be submitted to show all results.

Is there such a thing as to submit a form on page load? Which in essence I suppose I am asking.

Link to comment
Share on other sites

You shouldn't use javascript to solve this problem anyway, I'm sorry but it doesn't make sense to do it. You should only use javascript to enhance user experience, not for something that's absolutely necessary.

 

Especially for something like this. Default values are the best way to go for a search page, it will function just as well as if the form was submitted. If you absolutely must have the parameters in the url, as I said before you should use a header at the very top of the page (before any html) to redirect the page if there's no parameters, or a javascript or meta redirect to do as much.

 

if (!isset($_GET['term'])) {
     header('Location: page?term=&submit=Go');
}

 

This will give you your default values as if the form was clicked on with no changes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.