0

Searched hours online to no avail.

This should be fairly easy for anyone experience with PHP (aka not me!)

All i'm trying to do is create a text search box and send button.


1. Users will add a keyword and click send.

2. Link to an external website that loads with keyword in the url. eg, Searching for: Paper


action="http:www.domain.com/st=123&129ss=PAPER"

I got as far as (and being a complete PHP noob):

<?php
$keyword = htmlspecialchars($_POST['keyword']);
?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form method="post" id="searchform" action="http://www.domain.com/default.aspx?st=FT&ss=<?php echo 'keyword'; ?>" />
<input type="text" name="keyword" id="se" size="35"  onblur="if (this.value == '') {this.value = 'search...';}" onfocus="if (this.value == 'search...') {this.value = '';}" value="search..." class="text" />
<input type="submit" id="searchsubmit" class="submit" value="Send" />
</form>


</body>
</html>

so damn frsutrating despite getting close. With above example, entering and submitting a keyword does direct to the new site, but the echo doesn't show.

Any advice?? Would be appreciated.

Edited by fluffybunny69: n/a

4
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by ko ko
0

your form is submitting a value but php is not getting it .
so echo will print nothing

post data is sent to action =" " site

0

The problem is that $keyword isn't set until after you have sent the user to the other page. You should use javascript so send the user to the url instead of a form.

jQuery code would look like this:

$('#searchsubmit').click(function(){
var keyword = $('#se').val();
window.location = http://www.domain.com/default.aspx?st=FT&ss=+keyword;
});

Then just take the form tag off altogether and leave the input and submit fields.

Edited by xylude: n/a

0

Hi xylude,

I tried the above but can't get it working:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script src="http://code.jquery.com/jquery-1.5.js"></script>

</head>

<body>

<input type="text" name="keyword" id="se" size="35"  onblur="if (this.value == '') {this.value = 'search...';}" onfocus="if (this.value == 'search...') {this.value = '';}" value="search..." class="text" />
<input type="submit" id="searchsubmit" class="submit" value="Send" />

<script type="text/javascript">
$('#searchsubmit').click(function(){
var keyword = $('#se').val();
window.location = http://www.domain.com/default.aspx?st=FT&ss=+keyword;
});
</script>

</body>
</html>

The form is generate, but clicking with search term doesn't do anything.

Edited by fluffybunny69: n/a

0

your form is submitting a value but php is not getting it .
so echo will print nothing

post data is sent to action =" " site

Hi, Thankls for your reply. Would you know how to fix this with PHP?

0

The javascript method (above) isn't working... :(

Edited by fluffybunny69: n/a

0

<script type="text/javascript">
$('#searchsubmit').click(function(){
var keyword = $('#se').val();
window.location = http://www.domain.com/default.aspx?st=FT&ss=+keyword;
});
</script>

You need jquery library to work the above method. And window.location = 'http://www.domain.com/default.aspx?st=FT&ss='+keyword; is wrong. Should be window.location = 'http://www.domain.com/default.aspx?st=FT&ss='+keyword; You must link the jquery library to work the above method, or try with simple js.

<script type="text/javascript"
var keyword = document.getElementById('se').value;
window.location = 'http://www.domain.com/default.aspx?st=FT&ss='+keyword;
</script>

Hope this help.

Edited by ko ko: Syntax wrong

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.