jFormer DocumentationUsing jFormer

Processing Submissions

The 'onSubmit()' function

So you have created your form. and now its time to work with the data your users have submited. This brings us to processing submissions

All form submissions are handled are handled by a function created by you in your form.php called by default 'onSubmit', you can change that by using the option called 'onSubmitFunctionServerSide' inside the jformer object.

{onSubmit}($formValues)

Object | $formValues the 'onSubmit' function has only one parameter $formValues, which jFormer passes an object containing all of the form values. the structure of this object is pretty simple, its based on how you structure your form

The structure of the $formValues object can change in a few ways, but it is very intuitive and based on how you structure your form

$formValues->page->section->component

Example One

If you add your components directly to the jformer object, then they can be access directly via the $formValues variable

$formValues->component

Example Two

If you add your sections directly to the jformer object, then they can be access directly via the $formValues variable

$formValues->section->component

Example Three (instances)

Whenever you have a component or section that is instantiated, then it is an array inside of the $formValues object,

$formValues->page->section->component[index]

$formValues->page->section[index]->component

and if you are really having fun with instances

$formValues->page->section[index]->component[index]

Return Array

The 'onSubmit' function returns an associative array containing information for your form to display and process for your users. the keys are as follows:

Status

can be set to success or failure.

successPageHtml

HTML of a success Page, that will slide up upon successful completion of the form.

failurePageHtml

HTML of a failure Page, that will slide up upon successful completion of the form., but failed processesing

failureNoticeHtml

HTML that goes within a notice div, that shows up next to the Control buttons, does not create a new page.

failureHtml

HTML that goes within a div, that shows up below the Control buttons, does not create a new page.

successJs

Javascript that runs upon completion of the form

failureJs

Javascript that runs upon completion of the form

redirect

URL to redirect the browser to.

Next Page: Styling Forms

This page was last edited on April 18, 2011 at 3:26pm.

26 comments (add a comment)

Patryk yarpo Jar on 2011-07-06 12:48:32

I believe "onsubmit" would be better name as "onSubmit" is invalid in XHTML.

Patryk yarpo Jar on 2011-07-06 12:50:07

Sorry, I thougth it was about JS :/

Helga Himura on 2011-08-11 21:25:23

how do i can get value of variable from JFormComponentMultipleChoice component? is it array?

Peter on 2011-08-24 05:24:55

i get "processing" stuck, it never calls the onSubmit(), what do i do?

Soccerjf on 2011-08-25 21:03:58

Helga it depends if you use radio or checkboxes. Radio button use returns a string, check button use returns an associated array

complex on 2011-08-27 10:52:40

where exactly do you configure the processing form php filename, location and parameters?

Dav on 2011-09-28 07:36:18

Has anyone actually managed to process the form submitted variables??
Ive tried pretty much everything. Help please

KidNapped on 2011-10-24 11:40:15

This documentation is awesome !!

This is what is printed into the iframe:

<script type="text/javascript" language="javascript"> parent.contactFormObject.handleFormSubmissionResponse({"status":"success","response":{"failureHtml":"<h1 style=\"margin-bottom: .5em;\">Thanks for Contacting Us<\/h1><p>Your message has been successfully sent.<\/p>"}});
</script>

KidNapped on 2011-10-24 11:40:53

script type="text/javascript" language="javascript"
parent.cadastroFormObject.handleFormSubmissionResponse({"status":"success","response":{"failureHtml":"<h1 style=\"margin-bottom: .5em;\">Thanks for Contacting Us<\/h1><p>Your message has been successfully sent.<\/p>"}});

/script

CK on 2011-11-11 13:20:49

In order to get the form to submit properly you have to make..you guessed it. More changes that are undocumented.

All of the examples have the form in a single php file, non-classed. If you try and do the onSubmit it will fail everytime if you are just referencing jformer.php from another file. This is because they are using 'call_user_func' so it's trying to load 'onSubmit' from the jformer.php!

Solution:
If you are using a class called MyForm, and have a submit function of onSubmit (or whatever); go to the jFormer initialization line and add this:

[...] "onSubmitFunctionServerSide" => array('MyForm', 'onSubmit')

Then go to jformer.php and 'require_once' your class file you are using. Pain in the a** but I have confirmed it works.

That will then work, because it will call the class.

CK on 2011-11-11 13:50:39

PS - On submission, the function parameter $formValues spits out an object array:

E.g.
object(stdClass)[26]
public 'adminFormpropPage' =>
object(stdClass)[27]
public 'adminFormpropSection' =>
object(stdClass)[21]
public 'formName' => string 'Test Form' (length=9)
public 'formType' => string 'contact' (length=7)
public 'formDescription' => string 'Test' (length=4)
public 'adminFormqaPage' =>
object(stdClass)[24]
public 'adminFormqaSection' =>
object(stdClass)[25]
public 'questionType' => string 'text' (length=4)
public 'questionText' => string 'Test' (length=4)
public 'questionRequired' =>
array
...
public 'answerText' => null
public 'adminFormcontactPage' =>
object(stdClass)[22]
public 'adminFormcontactSection' =>
object(stdClass)[23]
public 'contactListName' => string 'Test Contacts' (length=13)
public 'contactClubs' => string '11111383' (length=8)
public 'contactPositions' => string 'all' (length=3)


Which you can then manipulate or stick into a DB, whatever.

CK on 2011-11-13 16:19:00

Use this as a basic to get all arrays of all objects.

public function onSubmitForm($formValues){
$data = self::fixData($formValues);

throw new Exception(var_dump($data));


}

public function fixData($data){
$fv = (array)$data;

foreach($fv as $key => $value){
if(is_object($value) && get_class($value) === 'stdClass'){
$fv[$key] = self::fixData($value);
}
if(is_array($value)){
foreach($value as $valK => $valV){
if(is_object($valV) && get_class($valV) === 'stdClass'){
$value[$valK] = self::fixData($vVal);
}
}
$fv[$key] = $value;

}

}

return $fv;
}

}

Nícholas André on 2011-11-13 19:47:18

You should make this documentation better...

dave on 2011-12-12 05:36:51

I really don't get it because my code works with :

return array('failureNoticeHtml' => json_encode($formValues));


but still stuck under processing when use this one :

return array('successPageHtml' = 'ok ';


This development is for a democratic web project on www.unitethe99.org , thanks for your help.

dave on 2011-12-12 05:38:31

I really don't get it because my code works with :

return array('failureNoticeHtml' => json_encode($formValues));


but still stuck under processing when use this one :

return array('successPageHtml' = 'ok ';


This development is for a democratic web project on www.unitethe99.org , thanks for your help.

dave on 2011-12-12 05:39:24

i had the same problem here when sending my comment, had to reload the page and send again the form ??????????

dave on 2011-12-12 05:40:53

new test because last message was send successfuly here. If you read this do not consider the last message.

dave on 2011-12-12 05:51:58

just made a test with :

return array('redirect' => 'RDM-affiche-citoyen.php');

and it's work fine so why 'successPageHtml' doesn't work ???

dave on 2011-12-12 06:02:02

i confirm that here too i get some time stuck on processing while i send a message.

micaell on 2012-01-16 07:07:43

Please, show working example of the recording obtained from the form data into the database.
Cool framework, but the documentation is incomplete (

Frank on 2012-02-01 05:31:01

// Create the form
$myForm = new JFormer('myForm', array('submitButtonText' => 'Delete', 'action' => 'delete_bank.php'));

Add the action when creating the form. It will reload the page 'sort of'

What I would like is that on submission, I have a confirm dialogue. How can this be done? Please help, I can help any problems which you have as far as I know how to solve them....

shawn on 2012-03-21 14:22:55

anyone know how to do a normal post submit and not an ajax json one ?

Nacho on 2012-04-06 02:22:23

'successPageHtml' doesn't work... :( it show 'Processing...' all the time in all the examples...

Some help?

Francesco on 2012-04-28 02:35:42

Is there a way to set a target _blank or _self or something like that? I haven't had any luck ;/ Any help?

Nacho, do you have the SuccessPageHtml in your directory? For it to work you need the correct HTML file / page loaded