ksmatthews Posted March 27, 2008 Share Posted March 27, 2008 HI Gurus, I recognise that php and javascript are two entirely different beasts with php working server side and javascript working client side. I have developed some comprehensive javascript libraries used only for client side validation in a big project. It now turns out that the client prefers php server side validation instead ... ! Is there any way of calling javascript functions from within php ?? Ajax comes to mind ... Steven M Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/ Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 There are ways, but which one to use depends on what you want to accomplish. The easiest way would be to echo the javascript function call Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/#findComment-502256 Share on other sites More sharing options...
ksmatthews Posted March 27, 2008 Author Share Posted March 27, 2008 Hi THere, Thanks for getting back. You say 'The easiest way would be to echo the javascript function call Smiley', How would that be done from within php ?? regards, Steven M Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/#findComment-502279 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 echo '<script type="text/javascript">callSomeFunction(\'arg1\', \'' .$phpVarAsArg2. '\')</script>'; Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/#findComment-502286 Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2008 Share Posted March 27, 2008 The reason for needing to validate all external data when it reaches the server is you cannot trust any external data. Validation using javascript in the form can only alert a legitimate visitor (who has javascript enabled) that a value was missing or what he entered was not of the correct format. Also, spam scripts don't actually fill in the form page, they submit data directly to the form processing code, so anything you do in the form has no affect against a spam script. Javascript executes in the browser. Php only outputs content to the browser, so it only has the ability to output javascript to the browser. To perform validation on the server when the data has been submitted would require that you write php code with the same functionality as your javascript code. Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/#findComment-502358 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Oh, he wants to call javascript on the server side? Check out JSP Link to comment https://forums.phpfreaks.com/topic/98171-calling-javascript-from-php/#findComment-502363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.