I have a problem in my project that i cant fix yet.
Im working with MySQL - PHP and everything is working OK but when I try to open "php/consult.php?consult=add" using the form below.
<form action="php/consult.php?consult=add" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
</form>
My browser doesn't change the URL to "php/consult.php?consult=add". Instead it shows only "php/consult.php", what have I done wrong?
Thanks for your answers and your time, and sorry for my english (it isn't too good xD).
This works if submitted - you don't need to add the query string - if it were an <a href="... then you would need the full query string for the url:
<form action="php/test.htm" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
<input type="submit" name="submit" value="Submit" />
</form>
This gives me my url + /php/test.htm?codecosult=ghrth&submit=Submit
ghrth was what I had typed.
If you are submitting it with a script leave the query string off and let the "GET" method deal with it - script here is in the head.
<script language="javascript">function submit_this(){this.form.submit();}</script>
</head>
<body>
<form name="form" id="form" action="php/test.htm" method="GET">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" id="codecosult" required/>
</td>
<div onClick="submit_this();">Submit</div>
This gives me my url + test.htm?codecosult=dfthwrth
dfthwrth was what I had typed.
This also works, though the <a href="...'s hrefis modified here by the keypress event each time a key is pressed (may not work in all browsers):
<input type="text" name="codecosult" onKeyPress="ahreff.href='php/test.htm?'+this.value;" required/>
Click Here
This might be of interest - a dropdown will pass its value in the same way:
dropdown menu doesn't function - it will now!
Related
I am using the value of search form Director1 to auto input in the value of "director_id_1" in the form CompanyDirectors, it is working.
However, if I use search form Director2 to auto input in the value of "director_id_2", it is working but meanwhile the value of "director_id_1" will be empty again.
So, how can I keep the auto input value of "director_id_1" after search Director2 ???
The below code is saved in the same page: Director.php
<h2> Company Director(s) - Input</h2>
<hr style="border: 1px dotted #2c1294;">
<form name="Director1" action="" method="POST" accept-charset="UTF-8" >
<input type="text" name="QueryDirector1" />
<input type="submit" name="DirectorName1" value="Search Name of Director 1 to input ID" />
</form>
<form name="Director2" action="" method="POST" accept-charset="UTF-8" >
<input type="text" name="QueryDirector2" />
<input type="submit" name="DirectorName2" value="Search Name of Director 2 to input ID" />
</form>
<hr style="border: 1px dotted #2c1294;">
<form name="CompanyDirectors" method="post" action="Director_insert.php" accept-charset="UTF-8" >
<b>ID of Director 1:</b>
<input type="number" name="director_id_1" required="required" value="<?php echo $director_id_1; ?>" >
<br>
<b>ID of Director 2:</b>
<input type="number" name="director_id_2" required="required" value="<?php echo $director_id_2; ?>" >
<br>
<input type="submit" name="submit" value="Submit">
</form>
Thank you very much for your help & support first !
If your question (which I find very hard to understand) is:
I want anything already submitted on the first form (Director 1) to be maintained upon submission of the second form (Director 2), and vice versa. How could I achieve this?
Then my answer would be use sessions or the database for persistence.
If I am understanding your question correctly, you do not understand that HTTP requests are (by nature) stateless. In other words: when you submit any form data, it is processed server-side and then ceases to exist. The "state" then disappears.
You could cache the submitted data temporarily in a $_SESSION[...] variable, or you could store it into the database (and retrieve it back out) or use HTML5 storage in the browser or do something less elegant like use hidden HTML inputs in the second form. (Or just use one form.)
Some useful links:
http://www.w3schools.com/php/php_sessions.asp
http://php.net/manual/en/session.examples.basic.php
https://en.wikipedia.org/wiki/Stateless_protocol
So for example:
<?php
session_start();
if (isset($_POST['DirectorName1'])) {
$_SESSION['directors'][1]['name'] = $_POST['DirectorName1'];
}
if (isset($_POST['DirectorName2'])) {
$_SESSION['directors'][2]['name'] = $_POST['DirectorName2'];
}
Then print the values from $_SESSION rather than $director_id_1 etc.
It's hard to help without a full copy of your code.
I am very new to php, I am having a problem passing data from textbox to a php variable to use it in an anchor tag. Below is the code i am using.
<form id="searchform" action="fetchvalues.php" method="get">
<input name="q" id="q" type="text" />
<input name="searchbutton" id="go" type="submit" value="" />
</form>
I want to pass value from searchbutton to anchor tag
Hello"
If you are using jquery in your project and want to do this on the front end, you can do:
<a id="someLink" href="http://www.example.com/?q=var" target="_blank">Hello"</a>
$('#someLink').attr('href', "http://www.example.com/?q=" + $('q').val());
With php you'd only be able to set the entered value of q on a post. (meaning when someone submits the form)
i.e.
Hello"
IF you need to populate the link href without a page refresh, you'll need to use javascript, if you want it to be populated after a form post, you can use php.
Be aware though that the link would need to be on the page set in your forms action attribute to populate the link
You should be aware that you take precautions when echoing out form submissions, however the level of questions suggests you've got more to learn before that. (No offense intended)
<form id="searchform" action="fetchvalues.php" method="get">
<input name="q" id="q" type="text" />
<input name="searchbutton" id="go" type="submit" value="" />
</form>
On your fetchvalues.php page
<?php
$val = $_GET['q'];
?>
then
Hello
You can do like this
<?php
if(isset($_REQUEST['searchbutton']))
{
?>
Hello
<?php
}
?>
My question is this:
How do I use a php function with an argument FROM MY php/html form?
I downloaded this php function script from intechgrity.
Link: http://www.intechgrity.com/?p=808
The function is: itg_fetch_image('http://the.image.url/pic.bmp')
What I'm doing:
1) On my website I have a php page.
2) What I did was copy all of the intechgrity php script and pasted it into my page (at the top, of course)
In my page I have this form, but nothing is happening.
<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="text" id="Stuff" name="Stuff" maxlength="30" value="<?=$img_url;?>" />
<button type="button" onClick="newSrc();">Do it!</button>
</form>
What am I doing wrong, how come when I hit submit the function is not working?
Something like this, maybe? (I didn't check through all the code you linked to.)
<?php
function itg_fetch_img($img_url, ...) {
etc.
}
$img_url = $_POST['Stuff'];
if (!empty($img_url)) itg_fetch_img($img_url, ...);
?>
<form action="" method="post">
<input type="text" id="Stuff" name="Stuff" maxlength="30" value="<?=$img_url;?>" />
<input type="submit">Do it!</button>
</form>
Note that button is now an input with type submit, and javascript function is removed.
<form action="">
<input placeholder="SEARCH" name="search_input" type="text"/>
<input type="submit" name="search_submit"/>
</form>
If people search by "Keyword Item" I want URL will be http://mydomain.com/search?keywords=Keyword%20Item
How can I do it? I know needs configure in form action, get etc.
Thanks in advance.
Update
When I am trying with this code
<form action="http://search.golfoutletsusa.com/search?" method="get">
<input placeholder="SEARCH" name="Keywords" type="text"/>
<input type="submit" name="search_submit"/>
</form>
The URL is: http://search.golfoutletsusa.com/search?Keywords=85&search_submit=Submit+Query
I just want "&search_submit=Submit+Query" will be removed from URL.
<?php echo $_GET["keywords"]; ?>
You will need to change the name of the text field from search_input to keywords though.
You should also consider using an id attribute along with the name. And as the other answer says, form action and method should be set correctly.
Solution:1
You can add the following code at the top of your search.php (or, whatever the processor file):
<?php
if(isset($_GET["search_submit"]))
{
$keywords = $_GET["Keywords"];
header("Location: search.php?Keywords=$keywords");
}
?>
OR
Solution:2
You can omit the name of submit button if it is not really necessary to give it a name. So instead of
<input type="submit" name="search_submit"/>
just use
<input type="submit" />
Set action of the form to search.php and method to get.
Then change the name of your input element to keywords.
But still the url won't be - http://mydomain.com/search?keywords=Keyword%20Item
It will be - http://mydomain.com/search.php?keywords=Keyword%20Item
Simply put everything in the form properties, only you have to select a file which will receive all this, /search will not suffice:
<form action="search.php" method="get">
<input type="text" name="keywords" placeholder="SEARCH" />
<input type="submit" name="submit" />
</form>
EDIT: In the search.php file you would get the variable contents with the get global variable like this:
$search_query = $_GET['keywords'];
After that you simply write the rest of the code to do the search... Note that this would lead to an URL like http://www.example.com/search.php?keywords=query
Background: The website I am working on has a search bar at the top. The user inputs a part code for a product and the website returns information about that product.
So, I have a basic search bar that posts parameters from a HTML form into a PHP script, which then does a lookup on a MySQL server to get the Product.
The problem is because some part codes have "#" characters, I have to use Javascript to insert escape characters, otherwise I only get some of the part code in the PHP script.
Example - 123#ABC would be read as 123.
I use a hidden value in the form, which is populated with the Text Box value, modified by the escape() function in Javascript.
This is my code currently, it works in every browser except for IE.
Any help would be much appreciated :)
<script language="jscript">
function changeTextBox()
{
hiddenSearch.value = escape(txtSearch.value);
formSearch.submit;
}
</script>
<form id="formSearch" name="Search" action="?page=search" method="post">
Search by <u>Part Code</u> or <u>Description</u>
<input id="txtSearch" type="text" size="35">
<input id="hiddenSearch" name="Search" type="hidden">
<input name="Submit" onclick='jscript:changeTextBox();' type="submit" value="Submit">
</form>
take a look at changes-- i think there were issues with your javascript.
<script language="jscript">
function changeTextBox()
{
document.getElementById("hiddenSearch").value = escape(document.getElementById("txtSearch").value);
this.submit();
}
</script>
<form id="formSearch" name="Search" action="?page=search" method="post" onsubmit='changeText()'>
Search by <u>Part Code</u> or <u>Description</u>
<input id="txtSearch" type="text" size="35">
<input id="hiddenSearch" name="Search" type="hidden">
<input name="Submit" type="submit" value="Submit">
</form>