Jump to content

Field-template context on frontend forms


Pete
 Share

Recommended Posts

I have another question about this code from soma / pete example. Since it would be dynamically creating the form fields, I suspect it can be used to sanitize dynamic as well.

                       // Form started before this code
                       // get fields from a template we require to complete this page
                        $template = $templates->get("update_profile");
                        // loop through the fields
                        foreach ($template->fields as $field) {
                        $fieldlabel = $template->fieldgroup->getField($field, true)->label;
                        $inputfield = $field->getInputfield($page);

                        // set default value if we have one
                        $inputfield->value = $member_page->get($field->name);

                        // markup, and render() here then end the foreach;
                        // form ends after these fields

But when the form is done, we need to sanitize. One would have to use code like this, and name at least the fieldtype and fieldname:

if($input->post->submit_details) {
       $sanitizer->text($input->post->contract);

Or do the same code from above and foreach again. Or maybe there is another way...

But what happens if one field will be text / textarea or something else?

I have tried to use the foreach again, and echo out the fieldtype, hoping I could use it to sanitize dynamic:

foreach($template->fields as $field){
    echo $field->name;
    echo $field->type;

But this gives me back "FieldTypePage" (in my case)... Logic thinking for text it would be FieldTypeText (I hope).

I am really hoping to see how Soma and Pete did this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...