Roxen.git / server / modules / tags / vform.pike

version» Context lines:

Roxen.git/server/modules/tags/vform.pike:1:   // This is a roxen module. Copyright © 2000 - 2009, Roxen IS.   // By Martin Nilsson      #include <module.h>   inherit "module";    - constant cvs_version = "$Id: vform.pike,v 1.57 2009/12/08 20:38:45 jonasw Exp $"; + constant cvs_version = "$Id$";   constant thread_safe = 1;      constant module_type = MODULE_TAG;   constant module_name = "Tags: Verified form";   constant module_doc = "Creates a self-verifying form.";      // maxlength is excluded so that it gets exported. value is included   // since not all widgets have a value attribute, and those who do add   // it themselves. - constant ARGS=(< "type", "min", "max", "scope", "min", "max", "trim", + constant ARGS=(< "type", "min", "max", "scope", "trim",    "regexp", "glob", "minlength", "case", "date",    "mode", "fail-if-failed", "ignore-if-false", "ignore-if-gone",    "ignore-if-failed", "ignore-if-verified", "optional", "value",    "disable-domain-check", >);    -  + // pass along some HTML5-specific attributes (<type>:<attribute>) + constant HTML5_ARGS = (< "number:min", "number:max", "range:min", "range:max" >); +  + constant HTML5_TYPES = (< "number", "email", "url", "tel", "date", "datetime", +  "datetime-local", "search", "month", "week", "time", +  "color", "range", >); +    constant forbidden = ({"\\", ".", "[", "]", "^",    "$", "(", ")", "*", "+", "|"});   constant allowed = ({"\\\\", "\\.", "\\[", "\\]", "\\^",    "\\$", "\\(", "\\)", "\\*", "\\+", "\\|"});      Parser.HTML verified;   Parser.HTML failed;      void create() {    verified = Parser.HTML()->
Roxen.git/server/modules/tags/vform.pike:79: Inside #if defined(VFORM_COMPAT)
   break;    }    m_delete(args, "is");    }    if(args->filter) {    args->regexp="^["+args->filter+"]*$";    m_delete(args, "filter");    }   #endif    +  int(0..1) no_html5 = 0; +     var = id->misc->vform_objects[args->name];       switch(args->type) { -  +  case "number": // fall through    case "int":    if(!var) var=Variable.Int(args->value||"");    // FIXME: Should check invalid integer formats in min and max.    var->set_range(args->min ? (int)args->min : Variable.no_limit,    args->max ? (int)args->max : Variable.no_limit);    break;    case "float":    if(!var) var=Variable.Float(args->value||"");    // FIXME: Should check invalid float formats in min and max.    var->set_range(args->min ? (float)args->min : Variable.no_limit,    args->max ? (float)args->max : Variable.no_limit);    break;    case "email":    if(!var) var=Variable.Email(args->value||"");    if(args["disable-domain-check"]) var->disable_domain_check();    break; -  +  case "datetime": +  case "datetime-local": +  if (!args["date"]) args["date"] = "%Y-%M-%DT%h:%m"; +  // fall through    case "date":    if(!var) var=Variable.Date(args->value||""); -  if(args["date"]) var->set_date_type( args->date ); +  if(args["date"]) { +  // Disable HTML5 if date format is incompatible +  if (args["date"] != "%Y-%M-%D" && args["date"] != "%Y-%M-%DT%h:%m") no_html5 = 1; +  +  var->set_date_type( args->date ); +  }    break;    case "image":    if(!var) var=Variable.Image( args->value||"", 0, 0, 0 );    break;   // case "upload":   // if(!var) var=Variable.Upload( args->value||"", 0, 0, 0 );   // break;    case "password":    if(!var) var=Variable.VerifiedPassword(args->value||"");    case "text":    if(!var) var=Variable.VerifiedText(args->value||""); -  +  case "color": // fall through +  case "tel": // ... +  case "week": +  case "month": +  case "time": +  case "search": +  case "url": +  case "range":    case "string":    if(!var) var=Variable.VerifiedString(args->value||"");    var->clear_verifications();    if(args->regexp) var->add_regexp(args->regexp);    if(args->glob) var->add_glob(args->glob);    if(args->minlength) var->add_minlength((int)args->minlength);    if(args->maxlength) var->add_maxlength((int)args->maxlength);       if(args->case=="upper")    var->add_upper();
Roxen.git/server/modules/tags/vform.pike:153:    }    else if(id->real_variables[args->name] &&    !(args->optional && id->real_variables[args->name][0]=="") )    {    if(args->trim)    id->real_variables[args->name][0]    = String.trim_all_whites(id->real_variables[args->name][0]);    var->set_from_form( id, 1 );    }    } +  +  string type = !no_html5 && HTML5_TYPES[args->type] && args->type; +     mapping new_args=([]);    foreach(indices(args), string arg) -  if(!ARGS[arg]) new_args[arg]=args[arg]; +  if(!ARGS[arg] || (type && HTML5_ARGS[type + ":" + arg])) new_args[arg]=args[arg];    -  +  if (type) new_args->type = type; +     vars=([ "input":var->render_form(id, new_args) ]);    if(var->get_warnings()) vars->warning=var->get_warnings();    id->misc->vform_objects[args->name] = var;    return 0;    }       array do_return(RequestID id) {    int ok=!var->get_warnings();    int show_err=1;    if((args["fail-if-failed"] && id->misc->vform_failed[args["fail-if-failed"]]) ||
Roxen.git/server/modules/tags/vform.pike:278:    return 0;    }    }    }   }      class TagVForm {    inherit RXML.Tag;    constant name = "vform";    -  // Should disable caching since this module make heavy use of +  // Should disable caching since this module makes heavy use of    // id->misc, which isn't intercepted by the cache system. But then    // again, disabling the cache can be just as bad, so we let it be a    // known misfeature that some combinations of vform and the <cache>    // tag fails (just as it always has been, btw).    //constant flags = RXML.FLAG_DONT_CACHE_RESULT;       class TagVInput {    inherit VInput;    }   
Roxen.git/server/modules/tags/vform.pike:476:    inherit RXML.Frame;    RXML.TagSet additional_tags = internal;    private StateHandler.Page_state state;       array do_enter(RequestID id) {    id->misc->vform_ok = 1;    id->misc->vform_verified=(<>);    id->misc->vform_failed=(<>);    id->misc->vform_xml = !args->noxml;    +  string wizard_id = Roxen.get_wizard_id_cookie(id); +  if (!sizeof(wizard_id || "")) { +  wizard_id = Roxen.set_wizard_id_cookie(id); +  } +  if (wizard_id != id->variables["_roxen_wizard_id"]) { +  m_delete(id->real_variables, "__state"); +  id->misc->vform_ok = 0; +  id->variables["_roxen_wizard_id"] = wizard_id; +  } +     state = StateHandler.Page_state(id);    state->register_consumer("vform");    if(id->real_variables->__state) {    state->use_session( StateHandler.decode_session_id(id->real_variables->__state[0]) );    state->decode(id->real_variables->__state[0]);    }    else    state->use_session();    id->misc->vform_objects = state->get() || ([]);   
Roxen.git/server/modules/tags/vform.pike:505:    sizeof(id->misc->vform_verified) &&    id->misc->defines[" _ok"] ) {    m_delete(id->misc, "vform_verified");    m_delete(id->misc, "vform_failed");    m_delete(id->misc, "vform_xml");    return 0;    }       state->alter(id->misc->vform_objects);    content = "<input name=\"__state\" type=\"hidden\" value=\"" + -  state->encode() + "\" />\n" + content; +  state->encode() + "\" />\n" +  "<input name=\"_roxen_wizard_id\" type=\"hidden\" value=\"" + +  Roxen.html_encode_string(id->variables["_roxen_wizard_id"]) + +  "\" />\n" + content;       m_delete(id->misc, "vform_objects");    m_delete(id->misc, "vform_verified");    m_delete(id->misc, "vform_failed");    m_delete(id->misc, "vform_xml");    m_delete(args, "noxml");    m_delete(args, "hide-if-verified");       if(!args->method) args->method="post";    if(!args->action) args->action=get_var("self", "page");
Roxen.git/server/modules/tags/vform.pike:529:    }   }      TAGDOCUMENTATION;   #ifdef manual   constant tagdoc=([   "vform":({ #"<desc type='cont'><p><short>    Creates a self-verifying form.</short> You can use all standard    HTML input widgets in this container as well.</p>    - <p>Other tags that is related and useful are <tag>default</tag> + <p>Other tags that are related and useful are <tag>default</tag>   and <tag>roxen-automatic-charset-variable</tag>.</p>      <ex-box>   <vform>    <vinput name='mail' type='email'>&_.warning;</vinput>    <input type='hidden' name='user' value='&form.userid;' />    <input type='submit' />   </vform>   <then><redirect to='other_page.html' /></then>   <else>No, this form is still not valid</else>