I have a URL : foo.php?name=adam&lName=scott
, and in foo.php
I have a form which gives me values of rectangleLength
& rectangleBreadth
with a submit button.
When I click this submit button with form action as $_SERVER['REQUEST_URI']
, I get this result URL: foo.php?rectangleLength=10&rectangleBreadth=5
(these values have been filled in by the user).
Notice that I am losing my previous values name
& lName
from the URL.
How can I keep them?
Also, keep in mind that I have to come back to foo.php
and if the user wants to submit the form again then the length and breadth values should change.
Once, I needed sorting the results in a table keeping the search results coming from GET. I did like that:
You can add two hidden fields in the form on the first target site, blabla.php in your case:
For a dynamic solution, use a foreach loop:
You may consider locking the dynamic approach down to a list of known possible keys:
$_GET['fromvs']
In VendorSearch.php, aftersession_start(),
$srchfor =""; $fromwhat = $_GET['fromvs']; $_SESSION['fromwhat'] = $fromwhat; $vs = $fromwhat;
Use hidden input to store URL passed variable
<div style='position: absolute; top: 10px; left: 400px;'><input type='hidden' hidden='hidden' id='fromvs' name='fromvs' value="<?php echo $_SESSION['fromwhat']; ?>"></div>
But this thie
Segment in Calling html .... Add a Subcontractor .... Assign Subcontractor Contracts ..... Log Out ....
Segment in target php: VendorSearch.php
A simpler solution to keep the URL unchanged by using http_build_query
Following code works for my project. Hope it help some. 1. In menu (calling html) I call VendorSearch.php. variable fromvs is used in URL. 2. The target php VendorSearch.php will do different jobs based on the value of $_GET['fromvs'] 3. In VendorSearch.php, aftersession_start(),
There are different ways to do this. All of them write the parameters they receive into a file, memory, or a database and retrieve them later with a key
The easiest method is something like a session variable: http://php.net/manual/en/features.sessions.php
The main setup is something like this (caution: that is unsecure code, make sure you only add session variables you want to keep, and sanitize user input!):
and now, as long as the user does not close the browser, you can access these variables with
$_SESSION[varname];