Cindy93
Cindy93

Reputation: 1300

Passing a value to current Page

How do I check the url if it has a parameter or not before passing? I need to pass the value of s on current page. When passing on current page 'index.php' it would look like this index.php?s=value How can i pass the value if the url has parameters like index.php?page=1 or index.php?orderby=asc so when i press the search button it would be something like this index.php?page=1&s=value or index.php?orderby=asc&s=value

<form  method="get">
            <p class="search-box">
                <label class="screen-reader-text" for="user-search-input">Search Members:</label>
                <input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search">

                <input type="submit" name="" id="search-submit" class="button" value="Search Members">
            </p>

     </form>

Upvotes: 0

Views: 519

Answers (5)

user3064914
user3064914

Reputation: 959

Try this

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="GET">
<p class="search-box">
<label class="screen-reader-text" for="user-search-input">Search Members:</label>
<a href="'.$_SERVER['PHP_SELF'].'?page='.$s.'"><input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search"></a>
<input type="submit" name="" id="search-submit" class="button" value="Search Members">
</p>
</form>

Upvotes: 0

Parixit
Parixit

Reputation: 3855

Here, in action whole url will be placed.

<form  method="get" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

You should keep current page as a `action along with query string, so that extra parameters will be added at last.

Upvotes: 1

Andrew
Andrew

Reputation: 5340

Use php, you can output the param in the form as a hidden value, e.g. to keep the page param

<form  method="get">
<input type="hidden" name="page" value="<?php echo htmlspecialchars(isset($_GET['page'])? $_GET['page']:''); ?>" />

Keep the htmlspecialchars when using $_GET['page'], or you will face XSS attacks.

Upvotes: 2

Rich Dolinsky
Rich Dolinsky

Reputation: 111

<?php 
if(isset($_GET['s'])
{
    *dostuffwiths
   "echo <input type='hidden' name='s' value='$s'>";
}
else
{
   echo "<input type='hidden' name='s' value='$s'>";
}

?>

Upvotes: 0

David Ansermot
David Ansermot

Reputation: 6112

YOu have to include the page incomming parameters in the "action" attribute of you tag.

Upvotes: 0

Related Questions