Page 1 of 2
Getting a value from a textbox in the same php form
Posted: Tue Jun 19, 2007 9:07 pm
by xrez
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi i am quite new to php and would like to get some help. My problem is that i want to get a value from a textbox in the same php form and pass it to another page. For example i have this:
Code: Select all
<?php
echo "<td><input type=\"text\" name=\"firstName\"></td>";
$aname = $_GET('firstName');
echo "<td><input type=\"button\" name=\"ClickMe\" value=\"Click ME\" style=\"font-size:7pt\" onclick=\"window.addedit.location='newpage.php?&thename='$aname';\"></td>";
?>
so essentially i want to create a variable and assign the value in the textbox to it and pass it to a new page. I have tried $_GET, $_POST and $_REQUEST and all of them dont work. Can someone please help me?
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Jun 19, 2007 9:11 pm
by feyd
May I suggest using sessions?
http://php.net/ref.session
Posted: Tue Jun 19, 2007 9:16 pm
by xrez
Is there another way besides using sessions? It seems like a simple task, which i htink should be something like $var = textbox.value or something like that, but in php it seems so complicated

Posted: Tue Jun 19, 2007 9:29 pm
by feyd
The most simple, but easily manipulated by users is to use a get request.
This doesn't need Javascript, as your variant appears to use. You simply need a normal link.
However your posted snippet will have execution errors first. Specifically, $_GET being referenced as a function.
Posted: Tue Jun 19, 2007 10:57 pm
by xrez
So how do i do it without the use of sessions?
Posted: Tue Jun 19, 2007 11:02 pm
by superdezign
Call session_start at the beginning of every page that utilizes the session, and save the session variables in the $_SESSION array. They will last until the user closes the browser (or waits about 30 minutes doing nothing).
Posted: Tue Jun 19, 2007 11:20 pm
by feyd
xrez wrote:So how do i do it without the use of sessions?
You simply need a normal link.
Take this very thread's link: viewtopic.php?t=69421 .. you're doing, pretty much, the exact same thing in Javascript. You just need to shift it from Javascript to a standard link.
Posted: Tue Jun 19, 2007 11:27 pm
by xrez
ok but how do i pass the value of the data in the textbox? the code $aVar = $_GET("atextbox") does not work
Posted: Tue Jun 19, 2007 11:49 pm
by feyd
xrez wrote:ok but how do i pass the value of the data in the textbox? the code $aVar = $_GET("atextbox") does not work
What code are you using now?
Posted: Wed Jun 20, 2007 12:01 am
by xrez
feyd wrote:xrez wrote:ok but how do i pass the value of the data in the textbox? the code $aVar = $_GET("atextbox") does not work
What code are you using now?
I'm using the code that i have on the first post in this thread
I think submit the form to the php it self.
Posted: Wed Jun 20, 2007 12:23 am
by yuva_web
hi
if [s]u[/s]
you have an html form then in action give like this action = <? $_SERVER["PHP_SELF"] ?>
then [s]u[/s]
you can get the varible valuse with in the php ,
pass the variable value in hidden to next page.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
Posted: Wed Jun 20, 2007 12:42 am
by feyd
xrez wrote:I'm using the code that i have on the first post in this thread
Okay.... Do you understand how to create a normal link with a PHP echo? Do you understand how to insert a variable in that echo?
Posted: Wed Jun 20, 2007 1:34 am
by xrez
feyd wrote:xrez wrote:I'm using the code that i have on the first post in this thread
Okay.... Do you understand how to create a normal link with a PHP echo? Do you understand how to insert a variable in that echo?
Nope... as you can figure out by now i am fairly new with php. If you could provide some light on this it would be great

Posted: Wed Jun 20, 2007 5:39 am
by superdezign
Code: Select all
if(!empty($_SESSION['someValue']))
{
echo '<textarea name="whatever">' . $_SESSION['someValue'] . '</textarea>';
}
else
{
// Redirect them back to a page or show a default version or something
}
Posted: Wed Jun 20, 2007 9:03 am
by feyd
xrez wrote:Nope... as you can figure out by now i am fairly new with php. If you could provide some light on this it would be great

Sorry, I don't do hand-holding. I suggest you experiment. You already have enough in your original snippet to do it.