formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Help with validation for FT3 #731

Open venom2403 opened 4 years ago

venom2403 commented 4 years ago

hello, firstly thank you for this great software.

I have upgraded formtools to 3.0.20 and now having problem with my server validation part.

I tried to change some piece of code in my php but still the data is not appearing on the backend and the validation keeps prompting me some errors.

I'm using API to submit my form.

Here is the part for validation:

`<?php require_once("../../form/global/api/API.class.php"); $api = new FormTools\API(); $fields = $api->initFormPage(3); // X would be your form ID

// validation time! $errors = array(); if (isset($_POST['txtSubmit'])) { $rules = array(); $rules[] = "required,subject,Please select a subject."; $rules[] = "required,fullname,Please enter your name."; $rules[] = "required,email,Please enter your email address."; $rules[] = "valid_email,email,Please enter a valid email address."; $rules[] = "required,comments,Please enter your comments.";

$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" => "txtSubmit", "next_page" => "thankyou.php", "form_data" => $_POST, "finalize" => true ); $api->processFormSubmission($params); } // it failed validation. Update $fields with the latest contents of the form data else { $fields = array_merge($_SESSION["form_tools_form"], $_POST); } } ?>`

Could anyone please help debug this as I'm stuck.

Thank you