SearchBar Help!

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

WillFTW

Feedback score
2
Posts
219
Reactions
98
Resources
0
You first are wrong by saying people won't help for free it's a requesting section some people are nice which I see you aren't its a simple task sir so stop being a bitch about it he was just asking for help... you really need 1.50 ffs.

And second I would suggest googling it Google is your friend :)
Thanks, Someone actually is a ethical person. I've tried searching google but the majority of the bits that come up don't help with my situation. I really just want to have a searchbar that takes the input and just puts it on the end of a url.
 

1amDev

Designer & Developer
Supreme
Feedback score
30
Posts
511
Reactions
844
Resources
0
Hey,

This isn't just "one line of code" haha.
You'd probably need to run the form through MySQL and check for hits. Haven't done a search bar like it yet (hasn't been requested for me) but that's the way I would take it.

I would try to help you out but I'm way too busy with projects. But this isn't as much as a simple and easy task that you seem to think it is. HTML, PHP, and SQL work. Good luck man :)

Best regards,
Michael // 1amDev
https://1amDev.com
 

dentmaged

Premium
Feedback score
2
Posts
110
Reactions
38
Resources
0
First of all, you need to have .htaccess redirects for /user/user123, you would need to add a rewrite rule to /user.php?user=user123 or something like that:
I believe this works (make sure apache mod_rewrite is enabled):
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule user/(.*)$ user.php?user=$1 [QSA,NC,L]
</IfModule>

Then you need some JavaScript, I'm going to use jQuery, because it's the easiest to use.
Make sure you add an id to your form (I've called it search-form).
Untested and I just woke up, but I believe it works.
Code:
$("#search-form").submit(function(event) {
    event.preventDefault();
    window.location.pathname = "/user/" + $("#search-form input.form-control").val();
});

UPDATE: user.php has to be in your root directory (htdocs or www). If you want it to be changed, just tell me.[DOUBLEPOST=1468657015][/DOUBLEPOST]And I was looking at your website and I found something really annoying when scrolling. Please add a z-index to ul.nav1.
 
Last edited:

polarline

Premium
Feedback score
46
Posts
835
Reactions
157
Resources
20
THIS WILL WORK!!
Code:
<form name="search_bar" action="" method="POST">
<input type="text" name="search_player" placeholder="Search Player" >
<input type="submit" name="submit" value="Search">
</form>

<?php
if (isset($_POST['submit'])){

//POST VALUES
$search_name = $_POST['search_player'];

//URL SETTINGS
$url = 'http://www.kmkits.com/user/'.$search_name;

//REDIRECT
echo '<script language="javascript">';
echo '    window.location.href = "'.$url.'"';
echo '</script>';

}//END IF FORM IS SUBMITTED
?>
 

dentmaged

Premium
Feedback score
2
Posts
110
Reactions
38
Resources
0
THIS WILL WORK!!
Code:
<form name="search_bar" action="" method="POST">
<input type="text" name="search_player" placeholder="Search Player" >
<input type="submit" name="submit" value="Search">
</form>

<?php
if (isset($_POST['submit'])){

//POST VALUES
$search_name = $_POST['search_player'];

//URL SETTINGS
$url = 'http://www.kmkits.com/user/'.$search_name;

//REDIRECT
echo '<script language="javascript">';
echo '    window.location.href = "'.$url.'"';
echo '</script>';

}//END IF FORM IS SUBMITTED
?>
In my opinion that is over complicated. It only requires a little bit of JavaScript.
 

WillFTW

Feedback score
2
Posts
219
Reactions
98
Resources
0
Hey,

This isn't just "one line of code" haha.
You'd probably need to run the form through MySQL and check for hits. Haven't done a search bar like it yet (hasn't been requested for me) but that's the way I would take it.

I would try to help you out but I'm way too busy with projects. But this isn't as much as a simple and easy task that you seem to think it is. HTML, PHP, and SQL work. Good luck man :)

Best regards,
Michael // 1amDev
https://1amDev.com
Turns out it is! Lol I just had to change the action to a redirect page lol!
 
Status
This thread has been locked.
Top