0

NVM 我现在已经想通了,原来我只是完全智障......

我一直在查看此 ValidForm Builder 的教程。我似乎找不到任何地方解释如何仅获取纯提交的数据。我不在乎数据是否存储在数组中,因为它们可以被操纵。我唯一能看到的是,当提交表单时,它会将数据存储在某种形式的电子邮件友好 html 代码中。

$objForm = new ValidForm("newsletterForm", "");
$objForm->addField("name", "Your name", VFORM_STRING, 
    array(
        "maxLength" => 255, 
        "required" => TRUE
     ), 
array(
    "maxLength" => "Your input is too long. A maximum of %s characters is OK.", 
    "required" => "This field is required.", 
    "type" => "Enter only letters and spaces."
     )
);
 $objForm->addField("email", "Email address", VFORM_EMAIL, 
    array(
         "maxLength" => 255, 
         "required" => TRUE
     ), 
     array(
        "maxLength" => "Your input is too long. A maximum of %s characters is OK.", 
        "required" => "This field is required.", 
        "type" => "Use the format name@domain.com"
     ), array(
         "tip" => "name@domain.com"
    )
);

 $objForm->setMainAlert("One or more errors occurred. Check the marked fields and try    again.");
$objForm->setSubmitLabel("Send");

$strOutput = "";

if ($objForm->isSubmitted() && $objForm->isValid()) {
    //Do something php here if the form is sumbitted correct
    //*** Set the output to a friendly thank you note.
    $strOutput = "Thank you for your interest.";
    } else {
    //*** The form has not been submitted or is not valid.
    $strOutput = $objForm->toHtml();
 }      

基本上我只需要原始数据,这样我就可以将它存储到我的数据库中......

4

1 回答 1

1

我是 ValidForm Builder 的开发者之一。让我帮你解决这个问题。

在 isSubmitted && isValid 语句中,您可以这样做:

if ($objForm->isSubmitted() && $objForm->isValid()) {

    // You can store it in a local variable or just use the result of getValue() directly.
    $strEmail = $objForm->getValidField("email")->getValue();

}

事实上,如果您想直接将值作为电子邮件直接发布,我们也有一些内置支持(因为大多数网站表单都是联系表单,我们认为这会很方便):

if ($objForm->isSubmitted() && $objForm->isValid()) {

    // Use strEmailBody as the HTML content of your e-mail message or wrap some fancy
    // styling around it before sending.
    $strEmailBody = $objForm->valuesAsHtml();

}

此外,不建议在数据库中保存“原始”发布数据。这是 ValidForm Builder 的主要目的之一:通过验证用户输入来防止 SQL 注入。众所周知:用户输入是邪恶的。

于 2012-09-07T16:19:53.987 回答