Reputation: 41
How does one pass a PHP variable stored on one page that is NOT in a form, go to another page where a function uses it?
The reason I need this is so a user can adjust their form they are using by adding more rows with a submit button.
This is what I want to achieve:
$maxrows = stores the total amount of rows currently on the page
user presses "add more rows button"
another page is loaded which has a function which adds $maxrows + 5
once complete, the page redirects to the form
the form redisplays the page with 5 more rows
Any ideas how this can be implemented?
Thanks
Preferably not in a session if possible!
Upvotes: 1
Views: 2710
Reputation: 11
Try using a session.
Put start_session();
at the beginning of your script.
You can store the number of rows in $_SESSION['max_rows']
.
Upvotes: 1
Reputation: 3066
you can use jQuery + ajax to achieve this. Here when you click on add more rows it will add up just dome elements with dynamic names. The concept can be understood from http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-form-elements/
Upvotes: 2
Reputation: 3765
You could use $_GET
instead of $_POST
.
You pass the variable in to the page via the url:
someurl.com/page.php?somevar=hello
Then in page.php
you can use $_GET['somevar']
which will equal "hello"
.
Upvotes: 1
Reputation: 26861
Use it with GET
parameters - include the variable in the URL that loads your new page like
http://example.com/file.php?maxrows=10
In file.php
you get it by using $_GET
instead of $_POST
Upvotes: 1