| | |
passing varaible between pages ussing sessions
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Solved Threads: 0
Hello, I have 2 php forms, the first that takes the input and sends it to the second form which checks to see if the fields are empty.
What I have to do is if both fields are not entered is return to the main page and highlight the field/s that is not fill with an asterix, If one of the fields was entered I need to return that value to the textbox on the first page and then link back to the first page to enter in the missing field.
here is the first page input.php
here is the 2nd page
I have the checks working ok, just not sure how to pass the value of a entered field gathered by form 2 back to that field on the first form and then how to send the asterix check either.
I assuming it needs to be done using the $_SESSION command somehow.
any help much appreciated
What I have to do is if both fields are not entered is return to the main page and highlight the field/s that is not fill with an asterix, If one of the fields was entered I need to return that value to the textbox on the first page and then link back to the first page to enter in the missing field.
here is the first page input.php
PHP Syntax (Toggle Plain Text)
$asterixFirst = ""; $asterixLast = ""; // check for asterix value if ($checkFirst == false) { $asterixFirst = "* required"; } else { $asterixFirst = ""; } if ($checkLast == false) { $asterixLast = "* required"; } else { $asterixLast = ""; } echo "<form action=\"inputcheck1.php\" method=\"post\">"; echo "<p>Enter first name: <input type=\"text\" name=\"first\" />", $asterixFirst, "</p>"; echo "<p>Enter last name: <input type=\"text\" name=\"last\"/>", $asterixLast, "</p>"; echo "<input type=\"submit\" value=\"Process\"/>"; echo "</form>"; ?> </body> </html>
here is the 2nd page
PHP Syntax (Toggle Plain Text)
<?php if ((checkFirst() == false) && (checkLast() == true)) { echo "First name needed"; } elseif ((checkFirst() == true) && (checkLast() == false)) { echo "Last name needed"; } elseif ((checkFirst() == false) && (checkLast() == false)) { echo "Both fields need filing"; } else { echo "First Name: ", $_POST['first']; echo "<p>Last Name: ", $_POST['last'], "</p>"; echo "<a href=\"emptyinput1.php\">return to main page</a>"; } ?> <?php function checkFirst() { $_POST['first'] = trim($_POST['first']); if (isset($_POST['first']) && $_POST['first'] !== '') { //echo "First Name: ", $_POST['first']; return true; } else { return false; } } function checkLast() { $_POST['last'] = trim($_POST['last']); if (isset($_POST['last']) && $_POST['last'] !== '') { //echo "<p>Last Name: ", $_POST['last'], "</p>"; return true; } else { return false; } } ?>
I have the checks working ok, just not sure how to pass the value of a entered field gathered by form 2 back to that field on the first form and then how to send the asterix check either.
I assuming it needs to be done using the $_SESSION command somehow.
any help much appreciated
Last edited by mr_scooby; Oct 13th, 2009 at 3:48 am.
1
#2 Oct 13th, 2009
Insert this at the top of both pages:
Then you can use
in the second file. In the first file you can use:
php Syntax (Toggle Plain Text)
if (! session_id()) session_start();
Then you can use
php Syntax (Toggle Plain Text)
$_SESSION['first'] = $_POST['first'];
php Syntax (Toggle Plain Text)
if (isset($_SESSION['first'])) // first name was set by second page, you can use it
Last edited by pritaeas; Oct 13th, 2009 at 4:39 am.
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
![]() |
Similar Threads
- How to maintain sessions with C++ code? (C++)
- passing sessions between pages (PHP)
- passing session (PHP)
- new window popup (HTML and CSS)
- A Funky ASP/SQL "opportunity" (ASP)
- Passing Information Between pages (PHP)
- pass variable (Java)
- Site Stats Help (Search Engine Optimization)
Other Threads in the PHP Forum
- Previous Thread: Profile user page
- Next Thread: Update query with syntax error
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date delete directory display download dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql structure syntax system table thesishelp tutorial update upload url validation validator variable video web xml youtube





