How can I add may parameters when submitting my form.
<form name="frmSearch" action="list-of-all-jobs/by-date" method="POST">
<input type="text" name="kewords" id="keywords">
</form>
I already Rewrite my url to list-of-all-jobs/by-date. I just want to add may keywords parameter in the action when submitting so that the link of the page must be site.com/list-of-all-jobs/by-date/keywords.
Post action - Appends form-data inside the body of the HTTP request.
The request parameters are added in the URL seperated by '&'.
In your case it will be
list-of-all-jobs/by-date?keywords=keys.
If you want to add many keys either provide many input fields or append the keys using using commas like
list-of-all-jobs/by-date?keywords=key1,key2`
And do the processing in the server by splitting the query string parameter by commas.
You can change the form action using jquery.
HTMl is:
<form name="frmSearch" action="list-of-all-jobs/by-date" method="POST">
<input type="text" name="kewords" id="keywords"/>
<input type="submit" id="submitaction"/>
</form>
Jquery is:
$('#submitaction').click(function(e)
{
$("form").attr('action', 'list-of-all-jobs/by-date?keywords='+$('#keywords').val());
});
Related
I have a script which is run with a parameter (e.g. details.php?studentid=10325).
On this script I have a form with the following form code so that the form data is sent to the current script. However, what's happening is that the script is running without the parameter. How do I preserve the parameter in this form code?
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Not really recommended, but you could add a hidden <input> tag with the studentid so it is sent back when you submit the form. Like so :
<input type="hidden" name="studentid" value="<?= $_GET['studentid'] ?>">
Leave the action blank, and the form will submit back to the current url
<form method="post" action="">
Keep in mind you have specified post method, so the form values will come thru in $_POST, whereas your studentid on the query string will be in $_GET['studentid'], you can work around that by using $_REQUEST['studentid'] instead, but make sure you don't have a field in the form also called studentid
I am working with PHP forms.
The opening form tag looks like this:
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
This generated the following HTML:
<form name="adv_search_form" action="index.php?&rel=common_listing&module=company&sort_option=&search_option=&show_max_row=15" method="GET">
When I submit this form, I land on a URL:
http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
But what I want is that
?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this?
Thanks in advance.
If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.
You need to add hidden fields for all these values. For example:
<input type="hidden" name="module" value="company" />
That is your from data.
You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.
So change this line
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
to this
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">
Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.
This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.
Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".
When I use <form action="code.php?id=1" method="post"></form>, the form id is passed in the URL. But when I write the same code by replacing 'POST' by 'GET', the id is not passed to the URL.
Why?
When you submit a GET form, the values from the form are appended to the action URL, as the "query string" after the ?. Specifying an existing query string in the action attribute of such a form creates an ambiguity. Browsers don't merge the two query strings, they just throw away the old query string and build the new one based on the form.
With a POST form, there is no ambiguity: the data from the form is sent separately from the URL, so there is no need for the query string to be over-written.
However, it's probably best not to mix the two kind of parameters, so the solution is always to include your extra parameters as hidden fields, then it will work with both GET and POST forms:
<input type="hidden" name="id" value="1">
Better way is to pass id in hidden field.
<form action="code.php" method="post">
<input type="hidden" value="1" name="id" />
</form>
If your form is as below
<form action="code.php?id=1" method="post">
<input typ"text" name="username" />
<input type="submit" />
</form>
example script in code.php
<?php
print_r($_GET);
print_r($_POST);
print_r($_REQUEST);
?>
You will get form data in post array and url parameters in get array, in request you will get both get and post data in one array. But if you change from post to get method your form data added with the url instead of appending. This issue is because of ambiguity. To get solution i this situation, create a hidden field in your form those you also want to send with query string.
I have a form on a page with get parameters:
index.php?PageID=12
I then have a multiple forms on that page which build up the page details as the user selects the details.
My problem is when the form is posted the Get overwrites other get parameters.
I can use post but then can only post the information back once as the post values are wiped when the next form is submitted;
the idea is the forms build up a address as such;
?PageID=12
?PageID=12&Section=48
?PageID=12&Section=48&Event=1456
and so on as the user selects more items.
Thanks for your help.
For forms with method=get the query string parameters specified in action attribute are ignored. Add such parameters as hidden form fields:
<form action="index.php" method="get">
<input type="hidden" name="PageID" value="12">
<input type="hidden" name="Section" value="48">
<input type="hidden" name="Event" value="1456">
</form>
You can use server-side script or JavaScript to add the query string parameters as hidden form fields.
Put the incoming $_GET params in hidden fields
you can use the below code in which you can initialize the parameter that already required to post
<form action="index.php" method="get">
Here all the parameter will join with index.php?.......
So if you required to pass some parameter by default then you can write index.php?para=1......
But don not leave it blank form action value, by default it will consider the same url that is in address bar.
May this will help you .........:)
I have a form in a file called "report.inc" and after this form is filled and submitted the result is shown in a file called "report_result.inc".
form definition:
<form method="post" action="index.php?page=report_result">
When the form method is "post" all is ok.
after submitting the form, the page I get is with the right url:
mna.co.il/index.php?page=report_result
I wanted to see the whole url with all the sent parameters, so I changed the form method from "post" to "get" like this:
<form method="get" action="index.php?page=report_result">
and now after submitting the form, the page I get is with url that misses the part of "page=report_result".
it looks like this:
"http://mna.co.il/index.php?locality=%D7%91%D7%90%D7%A8&street=%D7%90%D7%91%D7%A8%D7%94%D7%9D&hNumber=55&rooms=3&area=70&ask=380000&smscode=&x=45&y=14"
while it should be like this:
"http://mna.co.il/index.php?page=report_result &locality=%D7%91%D7%90%D7%A8&street=%D7%90%D7%91%D7%A8%D7%94%D7%9D&hNumber=55&rooms=3&area=70&ask=380000&smscode=&x=45&y=14"
What am I doing wrong?
Thanks in advance for all answers.
Anna
GET forms will wipe out any query string in their action when submitted. Use <input type="hidden"> to pass the data instead.
page=report_result is a GET parameter of the query so it's overridden by the params of your form if you use the GET method.
You should add the input
<input type="hidden" name="page" value="report_result" />
in your form and remove it from the action