FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Generated Forms

Populating Fields With Values From Other Fields

(2163 views. Last Updated: 2007-08-14 2:53 AM)

Here is an example that populates the value of one field with that of another. This example asks for:

Sales Rep Info:
Name
Phone

Billing Rep Info:
Name

If you leave the Billing Rep's Name blank then it will be populated with Sales Rep's Name after the user clicks submit.

Here's the example:
...
    $ffForm = new FfForm();
    $ffForm->addField(new SubmitField("ff_submit", "Submit"));
    $ffForm->addField(new SubmitField("ff_clear", "Clear"));
    $ffForm->addField(new SubmitField("ff_cancel", "Cancel"));
    $ffForm->addField(new HeaderField("sales", "Sales Rep Info"));
    $ffForm->addField(new PersonNameField("sales_name", "Name", FORM_FIELD_REQUIRED));
    $ffForm->addField(new PhoneNumberField("phone", "Phone", FORM_FIELD_NOT_REQUIRED));
    $ffForm->addField(new HeaderField("billing", "Billing Rep Info"));
    $ffForm->addField(new PersonNameField("bill_name", "Name", FORM_FIELD_NOT_REQUIRED));
    $ffForm->formFields["bill_name"]->setHelp("Leave this blank if it is the same as the Sales Rep.");
...
    class ConfirmButtonListener extends FfButtonListener
    {
        function onClick(&$ffForm)
        {
            //echo "CONFIRM<hr/>";
            if ($ffForm->checkValues()) {

                // SUBMIT OPERATION:
                $GLOBALS["action"] = FF_DONE;

                // If the Billing Rep's Name is blank then populate it with the Sales Rep's Name
                if (!$ffForm->getValue("bill_name"))
                    $ffForm->setValue("bill_name", $ffForm->getValue("sales_name"));
                ...
            }
        }
    }
...
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.