This topic is locked
[SOLVED]

 call javascrip function before redirect to php page

11/11/2013 1:20:09 PM
PHPRunner General questions
C
ccadivel author

Hello,

I have a dummy form (built on add page) on which the user enters several fields that need to be processed before passing to the list page (I put the redirection on before record added event : header("Location: QPI_list.php?Sexe=$Sexe&Param=$p")).

On the event before record added I'd like to process the fields entered (it will be the parameter passed to the redirected page) before the redirection.

The problem is that my javascript function is unknown (I got Fatal error: Call to undefined function myfunc() in C:\wamp\www\output\include\QPI_events.php ).
here is the piece of code from before record added event :

...

$South = $values["South"];

$Sexe = $values["Sexe"];
//naksahtra() function is declared in Add page after {END body} <script type="text/javascript" src="myscript.js"></SCRIPT>
$p = myfunc($Day, $Month, $Year, $Hour, $Min, $ZHour, $ZMmin, $DST, $LonDeg, $LonMin, $East, $LatDeg, $LatMin, $South);

header("Location: QPI_list.php?Sexe=$Sexe&Param=$p");

...
I look in the forum how to call a javascript function but couldn't find the answer to my problem.
Could someone help me please ?

Best regards,

Cris

Sergey Kornilov admin 11/11/2013

You are trying to call Javascript function from PHP code which doesn't make much sense.
Explain what you trying to achieve and we can suggest a better workaround.

C
ccadivel author 11/12/2013

I am collecting some input from a dummy page and process them (myfunc()) before passing the result ($p) to the list page which displays the data from a table using the parameters as filter.

Sergey Kornilov admin 11/12/2013

Do all processing in PHP code. As far as I understand your dummy page is Add page. Use BeforeAdd event in this case to perform all processing.

C
ccadivel author 11/12/2013

isn't it possible to do part of the processing in the client side, in add page for example. I add <script type="text/javascript" src="include/myfunc.js"></script> in Add page after {END body} but how can I call my function when click on save button then redirect to my list page ?

C
cgphp 11/13/2013

Check this manual page http://xlinesoft.com/phprunner/docs/how_to_ask_for_confirmation_before_saving_record.htm
Add your custom function call as follows:

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

your_function_call();

});
C
ccadivel author 11/13/2013

Hello,

Thank's everybody for the help, after different test I'll go for PHP code.

Regards,