NetTalk Central

Author Topic: Forcing the Cancel button or just cancelling the save  (Read 2651 times)

rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Forcing the Cancel button or just cancelling the save
« on: July 28, 2008, 02:54:36 PM »
I have a form I've created and it has a save and a cancel button.

I want to put some code in an embed and check if I click on the save button to either call another form (so I can tell the user it is invalid) or just put a message on the form and display the message.

So for now, let's say I want to redisplay a message. I have one on the screen called reservestatus and the value starts out at 'Reserving Item'.

So I click on the Save button.. in my code I need to know how to do 2 things. One is redisplay the message.. without calling the reserveform.

Right now in the embed Validate Insert Start I have

 p_web.SetSessionValue('reservestatus','Problem Reserving Item!')
 loc:invalid='Problem Reserving Item!'

 I tried do value::reservestatus and I got some giant message at the top of the screen.. like bad html.

The way it is it calls reserveform (not reserveform.htm my html page that has the tags in it)... and does not update the reservestatus value.

I would just like to redisplay the reserveform.htm or just the one variable reservestatus and leave it at that. The docs say I can change the value and call do value::reservestatus.. but that doesn't work (probably because I'm doing something wrong).

The other option I suppose is just to call another form... but I'm really not sure how to do that on the validate embed?

Any hints at validation would be appreciated.

Thanks,

Ray
VMT

Mike Grigsby

  • Sr. Member
  • ****
  • Posts: 380
    • Yahoo Instant Messenger - onthedotsoftware
    • View Profile
    • MyHomeAssets! Software (among others)
Re: Forcing the Cancel button or just cancelling the save
« Reply #1 on: July 28, 2008, 07:25:38 PM »
Hi Ray, I'm sure there are a lot of ways to do this, but if I'm reading your workflow right, what I do is store the message in the session queue, like you've done, then call another page (you can use a regular web page and not a form.

Then put the name of that page as the 'URL' for the Save button. Then I put a button or link on the web page to go back to the list, or wherever, or just a <a href="javascript:history.go(-2)">Go back to list</a>
Mike Grigsby
Credify Systems
Central Oregon, USA

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: Forcing the Cancel button or just cancelling the save
« Reply #2 on: July 29, 2008, 08:03:50 AM »
Hi Ray,

Let's start by covering a couple of bases, then move on from there.

a) Validation can happen at several points during the Form. There's what I call "immediate validation" where fields are checked, as they are entered, and there's also "before save" validation which happens after the save button is pressed.  Although the two are both doing valuation, the approach to "how to fail" is quite different. (hold onto this thought for a moment and we'll come back to it...)

b) The URL on the SAVE button is set when the form is _generated_. Also put the "everything was ok" URL in here. Typically when validation fails, it remains on the current form. So the Save URL is the "where to go when validation passes" link.

c) The recent pre-releases of 4.31 contain some extended (better) support for Immediate Validation, and an example, so if you're wanting to do immediate validation then perhaps work with this.
http://www.capesoft.com/ftp/public/prerelease/index.htm

For purposes of your question I'm gonna assume that we'll add some validation after the user presses Save. If the validation fails it will return to the form, if it succeeds it'll proceed to the URL you've set for the Save button. For now I won't discuss Immediate Validation.

The Validation you are going to add will take place in the ValidateRecord routine.  You could use ValidateInsert and ValidateUpdate, but ValidateRecord covers both the Insert and Update cases.

here you add what ever code you like to _test_ whether the form is valid. It's also one of the very few places where you can access File Variables directly (eg cust:invoicenumber) - but for non-file-variables you should use p_web.GetValue('whatever')

If the record is ok, you set nothing, and the server proceeds to the URL specified by the Save button.

If the record is not ok, then you set 3 things;

    loc:invalid = 'Loc:Login'
    p_web.SetValue('retry','LoginForm.Htm')
    loc:Alert = 'Login Failed. Try Again.'

The first is loc:invalid. Set this to the "name" of the invalid field. (This will provide a visual indicator to the user, and also set the cursor to the right place.) Notice the quotes, the name is in a string.

The second is the "retry" parameter. This (by default) contains the name of the form procedure, however in your case you want to set it to match the "current web page htm file name". This is the direct answer to one of your questions, by setting the retry parameter you can specify the URL it goes to now that it has failed.

The 3rd item is loc:alert. Whatever string you put in here will appear in red (which you can override) on the form as it appears. It will also (by default) appear as a popup on the client computer. This is all overrideable, but we'll worry about that later.

Cheers
Bruce