Search code examples
phpjqueryjquery-templates

what is the best way to check if a parameter is set in PHP within a jQuery template?


what is the best way to check a parameter is set in PHP within jQuery template?

I have this code:

var custID = '<?php echo htmlentities( $_GET['custID'] ); ?>';

I need to check that it is set, if it is set then echo that value, if it is not produce an error.


Solution

  • i'd say:

    <?php
     if(isset($_GET['custID']))echo "var custID = '".$_GET['custID']."';";
     else echo "alert('error');";
    ?>