Using submitNoResponse() with the Submit button

Assume you have set up your Movie Review Channel the way we have outlined in Cookie personalization example: a Movie Review Channel and described more thoroughly in Implementation details for this example. Everything should be working well, but it is not quite perfect. There are a couple of improvements you can make to your channel.

For one thing, even though you have essentially obviated any need for the user to go to the Forms Manager, users' form submissions are still sent to the Forms Manager, and the response (the debug information we receive from the setprefs.pl script) is still sent into your Forms Manager. This will not ruin anything, of course, but all the debug information is not a pretty sight.

While we are at it, the Your submission has been recorded and will be sent during the next Synchronization message could probably be personalized. Also, it is a little weird that as soon as a user finishes sending his submission, he is sent right back to the form he just filled out, with the values that existed before he entered his data. A user who is not familiar with the inner workings of your channel might think that his results were not processed.

Luckily, you can fix all of this with just one line.

Look at the Submit section of the form produced by the editprefs.pl script. Right now, it is just a standard Submit button. But M-Business Client allows a few customizations that let you tweak the submission options to work better with your channel.

For instance, within the editprefsform.pl script, we create the submit button with the following HTML:

<input type="submit" name="submit" value="Submit">

Instead, you can create it with this little bit of JavaScript:

<input type="button" name="submit" value="Submit" 
    onClick="document.forms[0].submitNoResponse( 
        'Your updated movie choices will be here next time you sync', 
        true, false); 
    back()" 
>

So what does this all mean? The rest of this section explains the JavaScript above.

The first line just creates a standard button. It is the onClick part that looks a little unfamiliar. We are calling a submitNoResponse() function that is specifically for M-Business Client.

The submitNoResponse() function uses the format:

submitNoResponse(confirmMessage, isHidden, isMulti)

The table below describes the arguments.

The submitNoResponse() function tells M-Business Client that you want to submit the results of this form, but to not keep the results in the Forms Manager. Note, however, that the results are still looked at for useful commands like Set-Cookie in the HTTP header. It is just not kept around after being viewed. Since the result of the setprefs.pl script is just some debug information, you want to use submitNoResponse() to hide those results.

Table 1. Arguments for submitNoResponse()

Argument

Description

confirmMessage

A string that includes the message you want to display to your user instead of the usual Your submission has been recorded... box.

isHidden

This boolean value determines whether you want the form to even be visible in the Forms Manager before submission. If you want users to have the ability to go into their Forms Manager and alter their data, then make this false. If you want the forms to be hidden immediately after submission (either for neatness sake, or because you have confidential information entered into a form that you do not want a casual observer to see), then make this true.

isMulti

This Boolean value determines whether you want to allow multiple form submissions. If this is set to false and the user enters data into a form more than once, only the most recent version will get sent to the server.

For example, if you have a user who changes his mind a lot and enters his preferences 87 different times before synchronizing, you do not want to process 87 different forms. You only want to process the most recent form, so you would set this to false. If you were making a stock ticker page, for example, and could reasonably expect a user to enter 5 different forms to indicate 5 different stocks to follow, you would set this to true.

Note: If you set isMulti to true, do not assume the forms will be processed in the same order they were entered into the mobile device. All forms in the Forms Manager are sent to be processed at once.

Note

The submitNoResponse() function is specific to the M-Business Client browser. If you try to run this page with Internet Explorer or Netscape, it will generate JavaScript errors. If you occasionally want to test your channel pages in IE first, start out with a normal Submit button. Then when you are ready to test it out on your mobile device, replace the Submit button with a submitNoResponse() button.

Finally, the back() command at the end is a piece of JavaScript that takes the user back to the previous page when he is all done editing his preferences. You probably do not want to keep the user around at this form once he is finished—the form will revert back to its prefilled out stage after the user is done with it, and it might trick him into thinking his data got thrown out.

There are some other interesting tricks you can pull with forms and JavaScript.

  • For M-Business Client 5.x and later JavaScript, see JavaScript.