Forum

Thread tagged as: Question, Api

API and form processing

I'm trying to build my first app for a project. Part of this requires a form to be added to a page for visitors to complete. I'm getting on OK but i'm struggling to figure out just how I go about actually saving the submitted form data into the app database table. Is there a specific method that does this? I can add the form to the page and can see the data being passed when the form processes, then I get lost.

I'm looking to save a text field and also an image field. When I look at the database I see that often data is stored in JSON format which makes me think I should be looking for a method that I can pass an encoded string to.

Any help or pointers appreciated. Also, is there an A to Z for the available api methods somewhere?

Graham Shedden

Graham Shedden 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you were creating a new kitten for a cats app, you might have something like:

<?php

$Template   = $API->get('Template');
$Template->set('kitten.html', 'cat');
$tags = $Template->find_all_tags_and_repeaters();

$Form = $API->get('Form');
$Form->handle_empty_block_generation($Template);

$Form->set_required_fields_from_template($Template, $details);

if ($Form->submitted()) {

    $data = $Form->get_posted_content($Template, $Kittens, $Kitten);

    if ($Kitten) {
        $Kitten->update($data); 
    }else{
        $Kitten = $Kittens->create($data);
    }

}

Hi Drew That's very helpful and much appreciated. Graham