Skip to content

Generating Form HTML

OneBadNinja edited this page Nov 29, 2017 · 3 revisions

Once fields and validation rules have been assigned, you may generate the HTML for the form using the generate() method. generate() must be followed by get_scripts() which outputs the necessary javascript needed to run the form.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Contact Us</title>
    <!-- default stylesheet -->
    <link rel="stylesheet" type="text/css" href="includes/handymail/assets/css/handymail.css"/>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>
    <h1><?php echo $form->name; ?></h1>
    <!-- Generate form HTML -->
    <?php echo $form->generate(); ?>
    <!-- Generate form scripts -->
    <?php echo $form->get_scripts(); ?>
</body>
</html>

Further customising generated code.

Supplying a boolean true argument to either generate() or get_scripts() will print the raw HTML and javascript code instead. You can take this and customise as desired.

Protip: do not delete or add any fields - run_validation() will prevent form submissions if fields are not explicitly defined with add_field(). This is an intended security measure.

Clone this wiki locally