I'm making a site in php and I'm using google custon search for my site.for this I'm using this code
<form action="http://192.168.0.113/boobloom/site/search.php" name="search" id="cse- search-box" >
<input type="hidden" name="cx" value="018095423333672301222:n5ebktimfxc" />
<input type="hidden" name="cof" value="FORID:9" />
<input type="hidden" name="ie" value="UTF-8" />
<div class="txt-box"><input type="text" name="q" /></div>
<div class="boob-img">
<input type="image" src="images/boob-img.jpg" name="sa" value="Submit" /></div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse- search-box&lang=en"></script>
but now my requirement is show the result on new page with Iframe.
I Never use Iframe before this.
how can I do this?thanks in advance..
finally I took code from Google Custom Search Engine and put the result in a page.and its working correctely
but the IFrame height is too much..
<script type="text/javascript">
var googleSearchIframeName = "cse-search-results";
var googleSearchFormName = "cse-search-box";
var googleSearchFrameWidth = 600;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="www.google.com/afsonline/show_afs_search.js"></script>
I try to change the FrameWidth variable to lower value but it still doesn't work..how can I do this?
var googleSearchFrameHeight = 300;
It's been a while since I worked with iFrames so this could be slightly wrong & need a bit of modification, but try this:
<form action="http://www.google.com/search" target="iframe" method="get" onSubmit="Gsitesearch(this)">
<input name="q" type="hidden" />
<input name="qfront" type="text" />
<input type="image" src="images/boob-img.jpg" value="Submit" />
And then the iFrame could look something like this:
<iframe name="iframe" src="" />
Basically, give the iFrame a name value & have URLs or form actions target it.
Hope this helped!
Related
I just cant get around this simple requirement. I am new to PHP and need help.
I need to capture the value in a Search Box and then pass it in the URL which opens in a new tab when hit on Submit.
What am I missing here..it seems like I am missing a lot of things for this to work..
<?php
if (isset($_POST["submit"])){
$example = $_post['searchon'];
echo '<a target = '_blank' href=http://www.amazon.in/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=.$example.&tag=orientmarketi-21></a>';
}
?>
<form action="index.php" method="post">
<input type="search" name="searchon" id="searchon" />
<input type="submit" name ="submit" />
</form>
try this code instead of your one:
<form action="http://www.amazon.in/s/ref=nb_sb_noss_1" method="get" target="_blank">
<input type="hidden" name="url" value="search-alias=aps" />
<input type="hidden" name="tag" value="orientmarketi-21" />
<input type="text" name="field-keywords"/>
<input type="submit" />
</form>
How to submit this form without using submit button. I want to submit it in loading this form,
<form name="frm1" id="frm1" action="../somePage" method="post">
Please Waite...
<input type="hidden" name="uname" id="uname" value="<?php echo $uname;?>" />
<input type="hidden" name="price" id="price" value="<?php echo $price;?>" />
</form>
You don't need Jquery here!
The simplest solution here is (based on the answer from charles):
<html>
<body onload="document.frm1.submit()">
<form action="http://www.google.com" name="frm1">
<input type="hidden" name="q" value="Hello world" />
</form>
</body>
</html>
You can try also using below script
<html>
<head>
<script>
function load()
{
document.frm1.submit()
}
</script>
</head>
<body onload="load()">
<form action="http://www.google.com" id="frm1" name="frm1">
<input type="text" value="" />
</form>
</body>
</html>
Do this :
$(document).ready(function(){
$("#frm1").submit();
});
You can do it by using simple one line JavaScript code and also be careful that if JavaScript is turned off it will not work. The below code will do it's job if JavaScript is turned off.
Turn off JavaScript and run the code on you own file to know it's full function.(If you turn off JavaScript here, the below Code Snippet will not work)
.noscript-error {
color: red;
}
<body onload="document.getElementById('payment-form').submit();">
<div align="center">
<h1>
Please Waite... You Will be Redirected Shortly<br/>
Don't Refresh or Press Back
</h1>
</div>
<form method='post' action='acction.php' id='payment-form'>
<input type='hidden' name='field-name' value='field-value'>
<input type='hidden' name='field-name2' value='field-value2'>
<noscript>
<div align="center" class="noscript-error">Sorry, your browser does not support JavaScript!.
<br>Kindly submit it manually
<input type='submit' value='Submit Now' />
</div>
</noscript>
</form>
</body>
using javascript
<form id="frm1" action="file.php"></form>
<script>document.getElementById('frm1').submit();</script>
You missed the closing tag for the input fields, and you can choose any one of the events, ex: onload, onclick etc.
(a) Onload event:
<script type="text/javascript">
$(document).ready(function(){
$('#frm1').submit();
});
</script>
(b) Onclick Event:
<form name="frm1" id="frm1" action="../somePage" method="post">
Please Waite...
<input type="hidden" name="uname" id="uname" value=<?php echo $uname;?> />
<input type="hidden" name="price" id="price" value=<?php echo $price;?> />
<input type="text" name="submit" id="submit" value="submit">
</form>
<script type="text/javascript">
$('#submit').click(function(){
$('#frm1').submit();
});
</script>
I can't seem to fix this (what I know is pretty simple) problem.
I'm creating a simple tag search that will search venues on my website.
It's set up so when multiple tags are selected it will bring back all results that have all the tags assigned to them. So I need some simple code that displays checkboxes on the homepage and alters the URL to
.../placecategory/venue/?place_tags=place+venue
I've come up with the following code (with just 2 options, for now) just to get it working
<form
action="<?php bloginfo('home') ?>/placecategory/venue/?place_tags=hall+stage"
method="get" accept-charset="utf-8">
<h2>Search</h2>
<input type="checkbox" value="hall" name="place_tags">
<label for="tag-105">hall</label>
<input type="checkbox" value="stage" name="place_tags">
<label for="tag-104">stage</label>
<input type="submit" value="Search">
</form>
The problem with this is it's changing the URL to
.../placecategory/venue/?place_tags=hall&place_tags=stage
which isn't pulling up the results on my site. How can i change this so that it removes the second &place_tags= (and every one after that)?
I can tell that i'm missing something silly but it's really frustrating me!!
Thanks in advance :)
Is this what you are looking for?
<form action="<?php bloginfo('home') ?>/placecategory/venue" method="get" accept-charset="utf-8">
<h2>Search</h2>
<input type="checkbox" value="hall" name="place_tags[]">
<label for="tag-105">hall</label>
<input type="checkbox" value="stage" name="place_tags[]">
<label for="tag-104">stage</label>
<input type="submit" value="Search">
</form>
You can parse thru this values with JS and put them into hidden input at once.
Try this:
include jQuery library to the head section:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
then in the body section
<script type="text/javascript">
function submit_me() {
var values = $.map($("input.get-me:checked"),function(input){
return input.value;
});
$('#hidden-input').val(values.join('+'));
$('#your-form').submit();
};
</script>
<input class="get-me" id="tag-105" type="checkbox" value="hall" name="one" />
<label for="tag-105">hall</label>
<input class="get-me" id="tag-104" type="checkbox" value="stage" name="two" />
<label for="tag-104">stage</label>
<img width="50" height="50" src="get.png" onClick="submit_me()" />
<form id="your-form" action="<?php bloginfo('home') ?>/placecategory/venue/" method="get" accept-charset="utf-8">
<input id="hidden-input" type="hidden" value="" name="place_tags" />
</form>
assign to your inputs class="get-me" and put your image into img. You have to only test this on other browsers then FF. Good luck.
I have a basic form that I am using as a dummy to test some JavaScript functionality. My goal is to click the submit button and have submission paused until a javascript function is executed, then submit the form after that. the code I currently have is below, but the submission of the form is not prevented, and the hidden field's value is never set. can someone explain why this is happening?
NOTE I am aware of a jQuery method of performing the same functionality. I am specifically trying to solve this problem without using jQuery. If your only answer is "jQuery is better", please do not bother.
<html>
<head>
<script type="text/javascript">
function test(){
document.getElementById("hidden").value="hidden";
var queryString = $('#decisionform').formSerialize();
alert(queryString);
document.getElementById("form").submit();
}
</script>
</head>
<body>
<?php
if ($_POST){
foreach ($_POST as $key=>$value){
echo "<b>$key</b> $value<br>";
}
}
?>
<form action="hello.php" method="post" id="form">
<input name="first" type="text" />
<input name="second" type="text" />
<input name="third" type="text" />
<input name="hidden" type="hidden" />
<input name="submit" type="submit" value="Submit" onclick="test();return false;" />
</form>
</body>
</html>
You don't have an element with the id hidden so document.getElementById("hidden").value="hidden"; will throw an error as you can't set properties on undefined. The script will stop running and never reach return false so the form will submit as normal.
try <form action="hello.php" method="post" id="form" onsubmit="test(); return false;">
to prevent a submit, you actually need to have a return false, in the onsubmit even of the form itself
along with not having an id on the hidden field.
<input name="submit" type="submit" value="Submit" onclick="test();return false;" />
use a regular button in this case because your function is performing the submit.
<input name="submit" type="button" value="Submit" onclick="test()" />
You're missing the id attribute from your input element. Modify <input name="hidden" type="hidden" /> to <input name="hidden" type="hidden" id="hidden" />.
You can use
onclick="return test()"
and just return false at the end of the function.
Add id="hidden" to your input, like this:
<input name="hidden" type="hidden" id="hidden" />
I have this form :
<form action="index.php?explore=browse" method="post">
<input type="hidden" name="artist" value="<?=$artist?>" />
<input type="hidden" name="event" value="<?=$event?>" />
<input type="hidden" name="date" value="<?=$date?>" />
<a onclick="this.form.artist.value=all; this.form.submit();return false" href="#">All</a>
</form>
and I'd like to know :
Why it doenst put the value "all" to the artist field?
Is this Javascript? Or easy HTML?
Is better translate this with jQuery/JS Handler or this is better? (light, crossbrowsers..and so on)
Hope you can help me!
You need to change the
this.form.artist.value=all;
to
this.parentNode.artist.value='all';
The way you use it makes two wrong assumptions
it assumes that links inside a form have a form attribute.. They do not. Only input elements have a form attribute. Using parentNode should do the trick for you particular case since the link is a direct child of the form element.
it expects a variable with name all exists and it tries to put the content of that variable in the input.
Making all be a string by wrapping it to single quotes ' should do what you want.
demo at http://jsfiddle.net/gaby/vzuFD/
With jQuery you could do
<form action="index.php?explore=browse" method="post">
<input type="hidden" name="artist" value="<?=$artist?>" />
<input type="hidden" name="event" value="<?=$event?>" />
<input type="hidden" name="date" value="<?=$date?>" />
<a id="all" href="#">All</a>
</form>
and
<script type="text/javascript">
$(function(){
$('#all').click(function(){
$(this)
.closest('form')
.find(':input[name=artist]')
.val('all')
.end()
.submit();
});
});
</script>
demo at http://jsfiddle.net/gaby/vzuFD/1/
If you want to use this JavaScript line then change your code with: this.form.artist.value="all"
Yes it is HTML with simple inline JavaScript.
You can use JQuery also by following changing :
First change your HTML Code with the following:
<form action="index.php?explore=browse" method="post">
<input type="hidden" id="artist" name="artist" value="<?=$artist?>" />
<input type="hidden" name="event" value="<?=$event?>" />
<input type="hidden" name="date" value="<?=$date?>" />
<a id="linkAll" href="#">All</a>
</form>
Then use the following jQuery :
$('#linkAll').click( function(){
$('#artist').val('All');
});
all is a reference to a variable that does not exist. 'all' is a string containing the text "all".
Additionally, you assume that this.form exists (but it likely doesn't). You could use parentNode instead, but this may stop working if you move the <a> tag.
So:
<form action="index.php?explore=browse" method="post">
<input type="hidden" name="artist" value="<?=$artist?>" />
<input type="hidden" name="event" value="<?=$event?>" />
<input type="hidden" name="date" value="<?=$date?>" />
<a onclick="this.parentNode.artist.value='all'; this.parentNode.submit();return false" href="#">All</a>
It's usually preferred not to write onclick handlers inside HTML, instead writing all your Javascript elsewhere in a dedicated Javascript block/file. It keeps things nice and separated.
We also prefer e.preventDefault to return false, here, though that's a little trickier to make cross-browser so I'll leave it for another question.)
Here's an example demonstrating an overall better solution:
<form action="index.php?explore=browse" method="post" id="theForm">
<input type="hidden" name="artist" value="<?=$artist?>" />
<input type="hidden" name="event" value="<?=$event?>" />
<input type="hidden" name="date" value="<?=$date?>" />
All
</form>
<script type="text/javascript">
var theLink = document.getElementById('theLink');
var theForm = document.getElementById('theForm');
theLink.onclick = function() {
theForm.artist.value = 'all';
theForm.submit();
return false;
};
</script>
A version of this with the use of jQuery might look like:
<script type="text/javascript">
var $theLink = $('#theLink');
var $theForm = $('#theForm');
$theLink.click(function() {
$theForm.find('[name=artist]').val('all');
$theForm.submit();
return false;
});
</script>