Skip to content

Instantly share code, notes, and snippets.

@lisandi
Forked from somatonic/form-example.php
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save lisandi/2fba925fd3a3204f987a to your computer and use it in GitHub Desktop.

Select an option

Save lisandi/2fba925fd3a3204f987a to your computer and use it in GitHub Desktop.

Revisions

  1. @somatonic somatonic revised this gist Jan 10, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions form-example.php
    Original file line number Diff line number Diff line change
    @@ -42,11 +42,11 @@
    $form->processInput($input->post);

    // here is a good point for extra/custom validation and manipulate fields
    $vemail = $form->get("email")->value;
    if($vemail && (strpos($vemail,'@hotmail') !== FALSE)){
    $email = $form->get("email");
    if($email && (strpos($email->value,'@hotmail') !== FALSE)){
    // attach an error to the field
    // and it will get displayed along the field
    $vemail->error("Sorry we don't accept hotmail addresses for now.");
    $email->error("Sorry we don't accept hotmail addresses for now.");
    }

    if($form->getErrors()) {
  2. @somatonic somatonic revised this gist Nov 6, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion form-example.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    <?php

    $out = '';

    // create a new form field (also field wrapper)
    $form = $modules->get("InputfieldForm");
    $form->action = "./";
    @@ -50,7 +52,7 @@
    if($form->getErrors()) {
    // the form is processed and populated
    // but contains errors
    $out = $form->render();
    $out .= $form->render();
    } else {

    // do with the form what you like, create and save it as page
  3. @somatonic somatonic revised this gist Nov 6, 2012. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions form-example.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    <?php
    $out = '';

    // create a new form field (also field wrapper)
    $form = $modules->get("InputfieldForm");
    @@ -51,15 +50,18 @@
    if($form->getErrors()) {
    // the form is processed and populated
    // but contains errors
    $out .= $form->render();
    $out = $form->render();
    } else {

    // do with the form what you like, create and save it as page
    // or send emails. to get the values you can use
    // $email = $form->get("email")->value;
    // $name = $form->get("name")->value;
    // $pass = $form->get("pass")->value;

    //
    // to sanitize input
    // $name = $sanitizer->text($input->post->name);
    // $email = $sanitizer->email($form->get("email")->value);
    $out .= "<p>You submission was completed! Thanks for your time.";
    }

  4. @somatonic somatonic revised this gist Nov 6, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion form-example.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    <?php
    $out = '';

    // create a new form field (also field wrapper)
    $form = $modules->get("InputfieldForm");
    @@ -50,7 +51,7 @@
    if($form->getErrors()) {
    // the form is processed and populated
    // but contains errors
    $out = $form->render();
    $out .= $form->render();
    } else {

    // do with the form what you like, create and save it as page
  5. @somatonic somatonic created this gist Nov 6, 2012.
    72 changes: 72 additions & 0 deletions form-example.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    <?php

    // create a new form field (also field wrapper)
    $form = $modules->get("InputfieldForm");
    $form->action = "./";
    $form->method = "post";
    $form->attr("id+name",'subscribe-form');

    // create a text input
    $field = $modules->get("InputfieldText");
    $field->label = "Name";
    $field->attr('id+name','name');
    $field->required = 1;
    $form->append($field); // append the field to the form

    // create email field
    $field = $modules->get("InputfieldEmail");
    $field->label = "E-Mail";
    $field->attr('id+name','email');
    $field->required = 1;
    $form->append($field); // append the field

    // you get the idea
    $field = $modules->get("InputfieldPassword");
    $field->label = "Passwort";
    $field->attr("id+name","pass");
    $field->required = 1;
    $form->append($field);

    // oh a submit button!
    $submit = $modules->get("InputfieldSubmit");
    $submit->attr("value","Subscribe");
    $submit->attr("id+name","submit");
    $form->append($submit);

    // form was submitted so we process the form
    if($input->post->submit) {

    // user submitted the form, process it and check for errors
    $form->processInput($input->post);

    // here is a good point for extra/custom validation and manipulate fields
    $vemail = $form->get("email")->value;
    if($vemail && (strpos($vemail,'@hotmail') !== FALSE)){
    // attach an error to the field
    // and it will get displayed along the field
    $vemail->error("Sorry we don't accept hotmail addresses for now.");
    }

    if($form->getErrors()) {
    // the form is processed and populated
    // but contains errors
    $out = $form->render();
    } else {

    // do with the form what you like, create and save it as page
    // or send emails. to get the values you can use
    // $email = $form->get("email")->value;
    // $name = $form->get("name")->value;
    // $pass = $form->get("pass")->value;

    $out .= "<p>You submission was completed! Thanks for your time.";
    }

    } else {
    // render out form without processing
    $out .= $form->render();
    }

    include("./head.inc");
    echo $out;
    include("./foot.inc");