Help! How do I do this in php?
I’m always getting tripped up in php because there’s no way that I know of to "call" or "run" from one php program to the next without form input.
I am collecting data on a Web form that needs to be passed to a server for processing. I have a form with action="calculate.php". When the user submits the form, calculate.php reads the form fields and does some calculations. This is where I need a "run" command. The calculated fields are to be processed by a program on the server. I don’t know how to fire off this program without another <form action=….> tag. In this case it’s stupid to have the user hit submit again just to send data to the server. There really isn’t anything for the user to review. And it’s not an option to do the calculations on the server because that’s a black box application (and I don’t have access to the server).
So the only way I can see it flowing is like this:
Enter data
Submit form
php program does calculations
Useless form appears
Submit form again
Server-side program does its thing
What am I missing here? Surely this has come up thousands of times.
Thanks,
Houyhnhnm
Deepak, I am totally ignorant in Ajax and very weak in JavaScript. I know how to do math in JavaScript but I have no idea how to pass the results to the server or the php script. I thought the whole idea of JavaScript was to keep everything local anyway…
can you use javascript to do calculations?
is it too complicated to do with client side ?
can you use ajax so that some other form does the calculation?
…………………..
if you can do math using javascript, then you can use hidden fields to send data to php script ..
i see that you say it is as a blackbox application, i wonder how can send input data to it. but hope you can use my suggestion..
ex: i assume that "F_Total" is input for your blackbox application! ( a post parameter for your application)
<input id="F_Tot" name="F_Total" type="hidden" />
( if you use "name" attribute in your html tag, you can get the value at php script after submit. this works in any server side languages)
do all calculations before you submit,
<script type="text/javascript">
function doyourcalculation(){
var result;
F_Tot = document.getElementById(‘F_Tot’); // find hidden field
.
.
.
calculations
result = 3 + 2;
.
.
if (result){ //if result is not nothing
F_Tot.value = result;
return true;
}
else
return false;
};
</script>
use return true or false for validations…
<input type="submit" value="submit" onclick="doyourcalculation()" />
if doyourcalculation has no error and returns true, hidden field has the input for your blackbox application.
good luck..
can you use javascript to do calculations?
is it too complicated to do with client side ?
can you use ajax so that some other form does the calculation?
…………………..
if you can do math using javascript, then you can use hidden fields to send data to php script ..
i see that you say it is as a blackbox application, i wonder how can send input data to it. but hope you can use my suggestion..
ex: i assume that "F_Total" is input for your blackbox application! ( a post parameter for your application)
<input id="F_Tot" name="F_Total" type="hidden" />
( if you use "name" attribute in your html tag, you can get the value at php script after submit. this works in any server side languages)
do all calculations before you submit,
<script type="text/javascript">
function doyourcalculation(){
var result;
F_Tot = document.getElementById(‘F_Tot’); // find hidden field
.
.
.
calculations
result = 3 + 2;
.
.
if (result){ //if result is not nothing
F_Tot.value = result;
return true;
}
else
return false;
};
</script>
use return true or false for validations…
<input type="submit" value="submit" onclick="doyourcalculation()" />
if doyourcalculation has no error and returns true, hidden field has the input for your blackbox application.
good luck..
References :