/    Sign up×
Community /Pin to ProfileBookmark

Why Url Changes ?

Folks,

Look at this form….

““
<form method=”GET” name=”search” id=”search” action=<?php echo $_SERVER[‘PHP_SELF’];?>?keywords=$keywords&limit=$limit&page=1>

<label for=”keywords”>Keywords</label>
<input type=”text” name=”keywords” id=”keywords” placeholder=”Type keywords”>
<br>
<label for=”result_limit”>Limit</label>
<select name=”result_limit” id=”result_limit”>
<option value=””></option>
<option value=”1″>1</option>
<option value=”10″>10</option>
<option value=”50″>50</option>
<option value=”100″>100</option>
<option value=”500″>500</option>
<option value=”1000″>1000</option>
</select>
““

Notice the url where it will be submitted.
It should be:
http://localhost/test/form.php?keywords=heman&limit=1

But instead, I am forwarded to:
http://localhost/test/form.php?keywords=heman&result_limit=1&search=+

Q1. Why “result_limit=” and not” “result=”?

Q2. How to rid “search=+” so that doesn’t show up on destination url ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerSep 12.2020 — > @developer_web#1623224 Q1. Why "result_limit=" and not" "result="?

``HTML<i>
</i>&lt;select name="result_limit" id="result_limit"&gt;<i>
</i>
``


That's why.
Copy linkTweet thisAlerts:
@developer_webauthorSep 15.2020 — @Nachfolger#1623227

@Nachfolger#1623227


<form method="GET" name="search" id="search" action=<?php echo $_SERVER['PHP_SELF'];?>?keywords=$keywords&limit=$limit&page=1>
<label for="keywords">Keywords</label>
<input type="text" name="keywords" id="keywords" placeholder="Type keywords">
<br>
<label for="limit">Limit</label>
<select name="limit" id="limit">
<option value=""></option>
<option value="1">1</option>
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
<br>
<button type="submit" name="search" id="search" value=" ">Search</button>
<br>
<button type="reset">Reset</button><br>
<br>
<br>
</form>

Look at this part above:

form method="GET" name="search" id="search" action=<?php echo $_SERVER['PHP_SELF'];?>?keywords=$keywords&limit=$limit&page=1>

I am forwarding to a url, be it SELF or otherwise, and the url does not contain "search+" nor "result_limit=" but "result=".

So, why add these onto the url after extracting the "name=" values ?

If $_GET method, by default, adds all the "name=" values onto the url then there is no need for me to add the params in the url is there ? Like so:


<form method="GET" name="search" id="search" action=<?php echo $_SERVER['PHP_SELF'];?>?keywords=$keywords&limit=$limit&page=1>


What is the use of adding the "limit=" onto the url if $_GET is gonna auto add it ?

But yet again if I don't add it then it won't know which value to add it to. I have to appoint it to add the $limit value.
Copy linkTweet thisAlerts:
@NachfolgerSep 15.2020 — > @developer_web#1623299 What is the use of adding the "limit=" onto the url if $_GET is gonna auto add it ?

I don't think you understand what a GET parameter is, or what the method='GET' actually means or does. Please look into it.
Copy linkTweet thisAlerts:
@developer_webauthorSep 15.2020 — @Nachfolger#1623301

All I know it ads params to existing or another url:

member.com/?user_id=111&gender=male

Now, we grab the params like so from url:

$user_id = $_GET['user_id'];

$gender = $_
GET['gender'];

I didn't know that the form

name="value"

gets added onto the url.

No tutorial taught me this. Can you find one that does ? I still guessing.
Copy linkTweet thisAlerts:
@NogDogSep 15.2020 — https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data#The_GET_method
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...