passing variables back to same original page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

passing variables back to same original page?

Post by revocause »

feyd | Please use

Code: Select all

,

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 cant figure out what the correct syntax or commands are for this. I made an HTML page , i would like the variables selected form drop down menus to then be sent to a PHP processing script, to do math and then send the resulting new variable back to the same HTML page and appear within an <input> text box .
Last edited by revocause on Tue May 29, 2007 2:45 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Umm... You send POST data to the same page by setting the action in your form to the same page. Then, put your PHP code in that page as well.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

right but..

Post by revocause »

but i want the php script handler in its own page. I could make tha tselect box work with javascript, but i need to use php
because eventually, I will populate those drop down menus as well.

do you know how php could pass that new variable back from a different script/page?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

here i found this example

Post by revocause »

here is an example i found on a website.

Im talking about the way they return those variables to that $ total box

thats similar to what i need to do.

page example:
http://www.brioprint.com/Products.aspx?ProductID=1
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Sessions. Sessions preserve data from one page to the next.

(I didn't look at the link you posted, but I'll assume it's e-commerce. If so, you're looking at sessions.)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why does the PHP processing page have to be in a different file than the PHP form page?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

i dont know if its sessions

Post by revocause »

The thing is, I was able to get a similar script working in the same HTML page, it worked like a standard javascript calculator. But,
I wanted to put it off the page into a php script.
Since its only a basic calculation math function, i dont understand why it cant just echo, print, or $_POST back to that input text box.


i could care less how the code changes, even if the handler.php has to be re-written , as long as it works.

any ideas?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

why it has to be in seperate page

Post by revocause »

the reason it has to be in seperate page , is because i want to keep the HTML clean from stacks of code , also, I want to re-use it and
possibly call on the php script from other pages.

:)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're going to need PHP in your code to get the value calculated by PHP anyway, so you may as well have it all on one page. You could easily do something like:

Code: Select all

<?php
$input_value = '';

if (!empty($_POST['field_to_calculate']))
{
    // Calculate
    $input_value = $calculation; // This would have been handled by the math
}
?>
<form method="post" action="<?php echo basename(__FILE__); ?>">
<input type="text" name="field_to_calculate" value="<?php echo $input_value; ?>" />
<input type="submit" name="submit_button" value="Submit Me" />
</form>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: why it has to be in seperate page

Post by superdezign »

revocause wrote:the reason it has to be in seperate page , is because i want to keep the HTML clean from stacks of code , also, I want to re-use it and
possibly call on the php script from other pages.

:)
HTML is pretty much unable to get the values alone. That link you posted... Do they use HTML? Nope. They use ASP.
The reason we have other languages is because HTML is limited. Use PHP and like it. :twisted:
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

really

Post by revocause »

i dont think some of you are actually reading through the initial question

now youre telling me to use more than HTML.

well, obviously.

if you read the initial post i made to start this topic, that was my question.
So far, I've been getting a few tangent responses.

but thanks
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

response to ORIGINAL question, to stay on track

Post by revocause »

If there is anyone on forum , that can respond to my initial topic question, I thank you.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Then maybe you need to reword the question. If you plan to put any variable into your "ans" box, you will need to be able to get the variable. That's where PHP comes in.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

revocause wrote:hi, i cant figure out what the correct syntax or commands are for this. I made an HTML page , i would like the variables selected form drop down menus to then be sent to a PHP processing script, to do math and then send the resulting new variable back to the same HTML page and appear within an <input> text box .
There is no syntax for this as HTML is a static markup language and cannot accept input data natively.

You may be able to achieve this with a server-side technology (ASP, PHP, JSP, Java, Ruby, Perl, Python, etc) in combination with some client side technology (Javascript), but what you are asking is not going to happen because HTML, by itself, is static.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

response super

Post by revocause »

super, please go back and re-read my initial question, asking how to get the 'ans' into the <input> text box, AND the php code i was attempting to use that wasnt quite working, which is why i asked about how to make that code work.

thanks
Post Reply