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
Problems with tutorial and repopulating fields
I studied the tutorial at to setup server-side validation. I had no trouble getting the validation to work by following the tutorial exactly. However, if the validation rules failed, it would not repopulate the fields that the user had submitted.

In particular, if I output the contents of $fields like this:

PHP Code:
$fields ft_api_init_form_page(5);

the only two values would be the form id and submission id, but none of the user data.

I was able to get it working as desired, but I had to deviate significantly from the tutorial. Here are the changes I made (I add comments to the areas I deviated from the tutorial code):

PHP Code:
//I don't retrieve the $fields here
//I setup a partial $params array for basic processing
$params = array(
"submit_button" => "Submit",
"form_data" => $_POST
$errors = array();
if (isset(
$_POST['Submit'])) {
$rules = array();
$rules[] = "required,BusinessName,Please enter your business name.";
$rules[] = "required,FirstName,Please enter your first name.";
$rules[] = "required,LastName,Please enter your last name.";
$rules[] = "required,Address,Please enter your address.";
$rules[] = "required,City,Please enter your city.";
$rules[] = "required,State,Please enter your state.";
$rules[] = "required,Zip,Please enter your zip.";
$rules[] = "required,Phone,Please enter your phone number.";
$errors validate_fields($_POST$rules);

    if (empty(
$errors)) {
//i add the additional params to finalize and go to thank you page
//if we pass validation
$params["next_page"] = "thank-you-sample.php";
$params["finalize"] = true;
//i always process the form, even if validation fails
//now i grab the $fields after the form has been processed
$fields ft_api_init_form_page(5); 

Is my approach valid? Did I miss something obvious in the tutorial?
Any opinion on this one? Looking forward to some input. Thank you.
Anyone willing to take a few minutes and respond to this? Either I'm missing something obvious, or there are likely other people who will be frustrated with the published tutorial in the documentation.
Hi jclermont,

Sorry for the wait - very busy week!

Yes, your approach looks fine - it's actually not bad at all! The only thing I'm not terribly thrilled about is calling the ft_api_init_form_page() function twice... nevertheless, it'll work fine without any side-effects that I can see.

The tutorial DOES needs updating - I'm very sorry for all the confusion its created. I'll make sure it gets done this Saturday.

Thanks for the very clear posts, jclermont! Very helpful!

- Ben
Thanks Ben! I look forward to seeing the solution you come up with.

I must say that I'm very impressed with FormTools. I'm going to study the code more, then pitch in and help with some of the open bugs on your issue tracker.
Problems with tutorial and repopulating fields are hard to find that is the reason many developers want help. It is a great place to find the help from the top professionals here. When i read the 99papers I come to know that it makes us easy to find a solution.

Forum Jump:

Users browsing this thread: 1 Guest(s)