Jump to content

Getting a value from a textbox in the same php form


xrez

Recommended Posts

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:

 

 

<?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.

 

I know you can do this really easily with .net or java, it would be just by saying something like $avar = textbox.value or something like that, but in php it seems a LOT more complicated :( ... Can someone please help me? 

If you post the current code to another page the varable firstname should echo on the other page,

 

but if you need to get a varable to another page while using the same page to post within use session's ok.

 

 

WARNING session_start(); needs to be on all pages that use the session.

 

 

<?php session_start();

$_SESSION['firstname']=$GET['firstname'];

// more code.
?>

 

// the page to display

 

<?php session_start();

echo $firstname;

?>

 

 

In this example someone clicks a link that moves a variable to the next page. The example uses $page, the page id.

 

<?php
// Define the variable you want to move to the next page...
$page = " DEFINE THIS";
?>

html code... LInk to the next page carrying the variable with it.
<a href="fav.php?page=<?php echo $page; ?>">

Code on the next page...
<?php
// Page ID
$page = $_GET['page'];
?>

 

I'm sorta confused on what you want to do. But this is an example of the method of "_GET." That you need to use.

If you post the current code to another page the varable firstname should echo on the other page,

 

but if you need to get a varable to another page while using the same page to post within use session's ok.

 

 

WARNING session_start(); needs to be on all pages that use the session.

 

 

<?php session_start();

$_SESSION['firstname']=$GET['firstname'];

// more code.
?>

 

// the page to display

 

<?php session_start();

echo $firstname;

?>

 

 

 

 

I have tried this but it doesnt seem to display the value on the other page  :(

In this example someone clicks a link that moves a variable to the next page. The example uses $page, the page id.

 

<?php
// Define the variable you want to move to the next page...
$page = " DEFINE THIS";
?>

html code... LInk to the next page carrying the variable with it.
<a href="fav.php?page=<?php echo $page; ?>">

Code on the next page...
<?php
// Page ID
$page = $_GET['page'];
?>

 

 

This is very close to what i want, but instead of :

 

$page = " DEFINE THIS";

 

 

i want $page to get the value from a textbox

if u will be dealing with big file you cant use get use post instead

 

or if u think the data wont reach the limitation of the session the use it but its not recommended

it slows down your site.

 

I simply cant understand y post is not working explain it plzz???

if u will be dealing with big file you cant use get use post instead

 

or if u think the data wont reach the limitation of the session the use it but its not recommended

it slows down your site.

 

I simply cant understand y post is not working explain it plzz???

 

 

Well for one i am not using form tags. All i want todo is get the value from a text field in the same php page and pass that value using javascript to another page.

Google it. I just googled this and found out the only way to do what you want to do is by JAVASCRIPT. Check out the tutorials, - they are great.

 

Otherwise, use form tags or session.

 

 

I did try to google this problem but to no avail. If you could provide some light on this situation that would be great

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.