FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation help for a NooB (JS?)
#5
(May 1st, 2017, 1:02 PM)eris667 Wrote: Bump?

Is this a internal or external form.  If external, can you paste it here?  Remove any sensitive info of course.

Here's a snippet for a single field and what is required for a external form.  All the below is in a single .php file, but pruned to just show the minimum fields.

Registration Page

PHP Code:
<?php
require_once("/xxx/xxx/formtool/global/api/api.php");
$fields ft_api_init_form_page(2);

// validation time!
$errors = array();
if (isset(
$_POST['sbmt']))
 
    {
 
   $rules = array();
 
    $rules[] = "required,firstname,Please enter your first name.";
 
    $rules[] = "letters_only,firstname,Please only use letters for your first name. *-No spaces/numbers/etc.";
 
    $errors validate_fields($_POST$rules);
 
   
// no errors - great! Now we process the page. The ft_api_process_form does
// the job of both updating the database and redirecting to the next page
 
   if (empty($errors))
 
        {
 
       $params = array(
 
           "submit_button" => "sbmt",
 
            "next_page" => "https://www.xxxx.com/wp/thank-you/",
 
            "form_data" => $_POST,
 
            "finalize" => true
            
);
 
        ft_api_process_form($params);
 
        
// it failed validation. Update $fields with the latest contents of the form data
 
   else
         
{
 
       $fields array_merge($_SESSION["form_tools_form"], $_POST);
 
        
 
   
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>Registration Form</title>
<link rel="stylesheet" type="text/css" href="registration.css">
</head>
<body>

<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
 
    {
 
   echo "<div class='error'>Please fix the following errors:\n<ul>";
 
    foreach ($errors as $error)
 
    echo "<li>$error</li>\n";
 
    echo "</ul></div>";
 
   
?>

<!-- Start of FORM -->
<div align="center">
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
  <table border="1" cellpadding="5" cellspacing="1" width="800">
    <tbody>
      <tr align="center">
        <td colspan="2" rowspan="1" valign="top"> <h2>HEADER 2</h2></td>
      </tr>
      <tr align="center">
        <td rowspan="1" colspan="2" valign="top" width="618"><BIG><BIG><B>TITLE<br>
        </td>
      </tr>
      <tr>
        <td align="right" valign="top" width="35%">First Name<br>
        </td>
        <td valign="top" width="618"><input maxlength="30" size="30" type="text" name="firstname" value="<?=@$fields["firstname"]?>" /> *-Required</td>
      </tr>
      <tr>
        <td colspan="2" rowspan="1" valign="top">
        <div align="center">Please confirm everything is correct before you submit!<br><input name="sbmt" value="Submit/Validate Form" type="submit"> </div>
        </td>
      </tr>
    </tbody>
  </table>
</form>
</div>
<!-- End of FORM -->
</body>
</html> 


You'll have to read through the options for the different field types, but the above should give you a base page to start with.  Hopefully, I didn't bork anything up by removing too much for this example.

Lyle
Reply


Messages In This Thread
Validation help for a NooB (JS?) - by eris667 - Feb 25th, 2017, 12:13 PM
RE: Validation help for a NooB (JS?) - by eris667 - Mar 4th, 2017, 8:06 PM
RE: Validation help for a NooB (JS?) - by eris667 - May 1st, 2017, 1:02 PM
RE: Validation help for a NooB (JS?) - by ocbroadband - Nov 2nd, 2017, 6:47 PM
RE: Validation help for a NooB (JS?) - by nelsondcosta - Aug 23rd, 2017, 7:19 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)