This PHP example program demonstrates how to create a form to display trigonometric function graphs.
<!DOCTYPE> <html> <head> <title>Graphing Form</title> </head> <body> <div style="width:604px;background-color:#F8F8F8;border:2px darkgray outset;padding:5px;"> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <fieldset> <legend>Function Graphing</legend> <label for="fn">Function:</label> <select name="fn"> <option value="sin" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'sin')) ? "selected" : ""); ?>>Sin</option> <option value="cos" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'cos')) ? "selected" : ""); ?>>Cos</option> <option value="tan" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'tan')) ? "selected" : ""); ?>>Tan</option> <option value="csc" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'csc')) ? "selected" : ""); ?>>Csc</option> <option value="sec" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'sec')) ? "selected" : ""); ?>>Sec</option> <option value="cot" <?php echo ((isset($_POST['fn']) && ($_POST['fn'] == 'cot')) ? "selected" : ""); ?>>Cot</option> </select><br /><br /> <fieldset> <legend>Range of x</legend> <input id="idLowX" type="number" name="lowx" step="0.01" value="<?php echo (isset($_POST['lowx']) ? $_POST['lowx'] : '-3.14') ?>" /> <input id="idHighX" type="number" name="highx" step="0.01" value="<?php echo (isset($_POST['highx']) ? $_POST['highx'] : '3.14') ?>" /><br /> </fieldset> <fieldset> <legend>Range of y</legend> <input id="idLowY" type="number" name="lowy" step="0.01" value="<?php echo (isset($_POST['lowy']) ? $_POST['lowy'] : '-3.14') ?>" /> <input id="idHighY" type="number" name="highy" step="0.01" value="<?php echo (isset($_POST['highy']) ? $_POST['highy'] : '3.14') ?>" /><br /> </fieldset><br /> <input name="FnSubmit" type="submit" value="Graph"> </fieldset> </form> <div style="width:604px;height:604px;"> <?php include 'CGraphYEqFX.php'; if (array_key_exists('FnSubmit', $_POST)) { $qGraph = new CGraphYEqFX(600, 600, floatval($_POST['lowx']), floatval($_POST['lowy']), floatval($_POST['highx']), floatval($_POST['highy'])); $qGraph->DrawGridLines(M_PI/8, M_PI/8); $qGraph->GraphFunction($_POST['fn']); echo '<img style="border:2px darkgray inset;" src="data:image/png;base64,'.base64_encode($qGraph->GetImageData()).'">'; } ?> </div> </div> </body> </html>
© 20072025 XoaX.net LLC. All rights reserved.