have you guys any ideas why the url is set in the $_GET, when i submit a form with post method?
I have a form like this:
<form action="/test/show/" method="post" enctype="multipart/form-data">
<input name="product" value="testing">
<input type="file" name="image">
<input type="submit" value="go" name="submit">
</form>
In my chrome i can see it will be send as post, but if i do this:
if (count($_GET) > 0) {
var_dump($_GET);
}
I get this result:
array(1) { ["url"]=> string(10) "test/show/" }
and i have no idea why?
Can you help me?
Under normal circumstances, with that URL, it wouldn't be. Presumably you are using mod_rewrite or similar to map /test/show onto something like /index.php?url="%2Ftest%2Fshow.
This is because PHP picked poor names for the $_GET superglobals.
An HTML form with method="GET" will put the data from its form controls in the query string, but that isn't the only way to request a URL with a query string.
$_GET contains data from the query string irrespective of the request method.
Related
Sorry if this question is a bit basic, but how can you parse form inputs in the Go Iris framework?
Here is the form I am using
<form action="/" method="post">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" value="Login">
</form>
here is the route and the controller respectively
iris.Post("/", TestController)
func TestController(c *iris.Context){
username := c.Form.Get("username")//Doesn't work
password := c.Form.Get("password")//Doesn't work
}
how do I retrieve the values in the Post request after the form has been submitted, Thanks
Based off an example on the iris github page you could try c.PostValue("Username"). The code you have may also work but I think you need to capitalize the variable names. In the html template you can see the name value is lowercased, however your context is more likely going off those the variable names to the left of the actual html like Username.
So I'm using a form in a specific page and I want to pass the exact search query to another url after submission
Example: I search for vehicles and I need the result to be domain.com/search/vehicles
So this is what I have so far:
<form id="" action="domain.com/" method="get">
<input type="text" name="search" />
<input type="submit" value="click here" />
</form>
The actual url result here is: domain.com/?search=vehicles
I can't figure out how to make it work
HTML forms will send the inputs in it as GET or POST (or DELETE or PUT also, I think) parameters. So they will send it as url?parameter1=xxx, they won't incorporate them in the url as you want like this url/parameter1/xxx/. I think to do it as you want is easier with jQuery (or plain javascript).
You can do this with jQuery, for example:
$("#form-id").submit(function() {
event.preventDefault(); // stops form from executing normal behavior
var newUrl = // get new url parameters and mount it;
document.location.href = newUrl; // sends to new location
/* Do Something */
return false;
});
document.location.href in javascript will redirect you to a new page.
We have a form:
<form name=input action=https://www.foo.com method=get>
<input type=hidden name=foobar>
<input type=hidden name=ticket>
<input type=text value=bar>
<input type=submit value=IN>
</form>
then in the end we will get:
foobar=&ticket=
but we need
foobar=ticket=
...what is the syntax for creating an HTML form that will put "=" instead of "&" in given places?
Replace
<input type=hidden name=foobar>
<input type=hidden name=ticket>
with
<input type="hidden" name="foobar" value="ticket"/>
The bit after the = is the parameter's value, so this is saying "submit a parameter called foobar with the value ticket."
The & comes from the "application/x-www-form-urlencoded" enctype of the form, which is the default. The other options available are described in the HTML standard, but the short story is that the encoding you want is not possible with a standard HTML form.
If Javascript is an option, you could try overriding the submission process and read the form values, building your own string according to your requirements, and direct the browser to the resulting URL.
I have a feeling this problem would be better solved by making the server at the "action" URL take the parameters in the standard & way, though...
I'm having a form with only one submit button. I don't know why, but when I use this code and I click on the submit button, nothing is happening. If I use a ! before the isset you'll see the echo in the page. I don't know what's wrong with it.
<form>
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Maybe, form by default is sending variables by get, try using method="POST" attribute in form tag
You have to set the method to POST.
Otherwise you can use:
$_REQUEST['addImg']
The variable $_REQUEST can access both GET and POST parameters.
Form needs an action and a method.
<form action="" method="post">
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Regarding "isset", if $_POST['addImg'] is not set, it doesn't echo "haaallloooo".
isset — Determine if a variable is set and is not NULL
Check http://hk.php.net/manual/en/function.isset.php
Is it possible to add groovy code to grails form?
I have a form:
<g:uploadForm controller="document" action="save" method="post">
<input type="file" name="dataFile" />
<input type="submit" id="addDocument" value="<g:message code=messages.document.save"/>">
</g:uploadForm>
I need to add code that puts the URL segments to the parameter value.
You're using a POST (because it's an upload and that's correct) method in your form, so you will not see the params in the URL. The params will get there (to the controller you redirect the request to), but won't show at the URL. In any case, you should go with hidden inputs in your form. Like:
<input type="hidden" id="foo" value=""/>
In your controller, you can get the parameters set in your input hidden fields simply by accessing the params map:
params.foo
Use hidden fields inside the form.