Jump to content

calling javascript from php


ksmatthews

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.