Page 1 of 4

passing variables back to same original page?

Posted: Tue May 29, 2007 9:48 am
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 .

Posted: Tue May 29, 2007 9:52 am
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.

right but..

Posted: Tue May 29, 2007 10:05 am
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?

here i found this example

Posted: Tue May 29, 2007 10:10 am
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

Posted: Tue May 29, 2007 10:17 am
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.)

Posted: Tue May 29, 2007 10:27 am
by RobertGonzalez
Why does the PHP processing page have to be in a different file than the PHP form page?

i dont know if its sessions

Posted: Tue May 29, 2007 10:29 am
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?

why it has to be in seperate page

Posted: Tue May 29, 2007 10:31 am
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.

:)

Posted: Tue May 29, 2007 10:37 am
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>

Re: why it has to be in seperate page

Posted: Tue May 29, 2007 10:42 am
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:

really

Posted: Tue May 29, 2007 10:50 am
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

response to ORIGINAL question, to stay on track

Posted: Tue May 29, 2007 10:52 am
by revocause
If there is anyone on forum , that can respond to my initial topic question, I thank you.

Posted: Tue May 29, 2007 10:54 am
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.

Posted: Tue May 29, 2007 10:56 am
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.

response super

Posted: Tue May 29, 2007 10:56 am
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