Re: [WebDNA] math and blank /no value
This WebDNA talk-list message is from 2014
It keeps the original formatting.
numero = 111444
interpreted = N
texte = --53bebfeb_238e1f29_623bContent-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: quoted-printableContent-Disposition: inlineIt=E2=80=99s generally a good idea at the top of your page to verify that= all the required parameters are passed into a page with valid values, an=d that optional parameters are given reasonable default values.I set local variables at the top of my page and default the values to som=ething reasonable if they are not passed in, then use the local variable =throughout the rest of the page.=5Btext multi=3DT=5DtAddListingPrice=3D0&tPromoTopspotPrice=3D0&tPhotoUpd=atePrice=3D0=5B/text=5D=5Bformvariables name=3Dad=5Flisting=5Fprice=5D=5Btext=5DtAddListingPrice==3D=5Bvalue=5D=5B/text=5D=5B/formvariables=5D=5Bformvariables name=3Dpromo=5Ftopspot=5Fprice=5D=5Btext=5DtPromoTopspot=Price=3D=5Bvalue=5D=5B/text=5D=5B/formvariables=5D=5Bformvariables name=3Dphoto=5Fupdate=5Fprice=5D=5Btext=5DtPhotoUpdatePr=ice=3D=5Bvalue=5D=5B/text=5D=5B/formvariables=5DSo if photo=5Fupdate=5Fprice was not passed in, tPhotoUpdatePrice would h=ave a value of 0.To protect against bad values passed in, such as expecting a number but g=etting something else, you could add a =5Bmath=5D context around the =5Bv=alue=5D like this:=5Bformvariables name=3Dphoto=5Fupdate=5Fprice=5D=5Btext=5DtPhotoUpdatePr=ice=3D=5Bmath=5D0=5Bvalue=5D=5B/math=5D=5B/text=5D=5B/formvariables=5DNow if photo=5Fupdate=5Fprice was blank or passed in as =E2=80=9Cmonkey b=rains=E2=80=9D, tPhotoUpdatePrice would be 0.You can also add range checks afterward to make sure the values are reaso=nable:=5Bif (=5BtPhotoUpdatePrice=5D<0) =7C (=5BtPhotoUpdatePrice=5D>1000)=5D=5B=then=5D**=C2=A0Complain loudly and don=E2=80=99t process the request **=5B/then=5D=5B/if=5D=46rom then on, reference the variables you created instead of the formva=riables passed in:=5Btext=C2=A0=C2=A0show=3D=46=5Dtotalcharges=3D=5Bmath=5D=5BtAdListingPri=ce=5D+=5BtPromoTopspotPrice=5D+=5BtPhotoUpdatePrice=5D=5B/math=5D=5B/text==5DOne final comment - passing pricing information into a page via URL or fo=rm parameters is dangerous and opens you up to clever users manipulating =the parameters and therefore manipulating the price.Brian =46riesOn July 5, 2014 at 6:23:33 PM, Kenneth Grome (ken=40webdnasolutions.com) =wrote:Or just prepend a zero to each value: =20=5Btext=5Dtotalcharges=3D=5B=21=5D =20=5B/=21=5D=5Bmath=5D=5B=21=5D =20=5B/=21=5D0=5Bad=5Flisting=5Fprice=5D=5B=21=5D =20=5B/=21=5D+0=5Bpromo=5Ftopspot=5Fprice=5D=5B=21=5D =20=5B/=21=5D+0=5Bphoto=5Fupdate=5Fprice=5D=5B=21=5D =20=5B/=21=5D=5B/math=5D=5B=21=5D =20=5B/=21=5D=5B/text=5D =20Regards, =20Kenneth Grome =20WebDNA Solutions =20http://www.webdnasolutions.com =20Web Database Systems and Linux Server Management =20On 07/05/2014 05:32 PM, Stuart Tremain wrote: =20> This will fix your problem: =20> =20> =5Btext show=3D=46=5Dtotalcharges=3D=5Bmath=5D=5B=46ORMAT =20> .2f=5D=5Bad=5Flisting=5Fprice=5D=5B/=46ORMAT=5D+=5B=46ORMAT =20> .2f=5D=5Bpromo=5Ftopspot=5Fprice=5D=5B/=46ORMAT=5D+=5B=46ORMAT =20> .2f=5D=5Bphoto=5Fupdate=5Fprice=5D=5B/=46ORMAT=5D=5B/math=5D=5B/text=5D= =20> =20> If any of your values are blank they will be formatted to 0.00 so =20> that your math will then be able to calculate without error. =20> =20> Regards =20> =20> Stuart Tremain =20> ID=46K Web Developments =20> AUSTRALIA =20> webdna=40idfk.com.au =20> =20> =20> =20> =20> On 6 Jul 2014, at 1:57 am, Rich Kwas > wrote: =20> =20>> Hope everyone in the US had a nice 4th of July..... =20>> Chicago stopped its lakefront fireworks extravaganza years =20>> ago.... ;( =20>> =20>> =20>> A somewhat simple =5Bmath=5D addition snippet is driving me nuts =20>> =20>> I've seen this referenced one way or another in the talklists..... =20>> =20>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20>> Another trick for dealing with fields that may be blank is to =20>> prepend =20>> them with a 0 within =20>> the *math* context:=5B*math*=5D=5B=5Fitemamount=5D+=5B=5Fpostage=5D+0=5B==5Fdonation=5D=5B/*math*=5D =20>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20>> =20>> =20>> Doesn't behave as mentioned that way for me..... =20>> =20>> =20>> I'm ultimately snatching some price values and doing simple =20>> addition: =20>> =20>> =5Btext =20>> show=3D=46=5Dtotalcharges=3D=5Bmath=5D=5Bad=5Flisting=5Fprice=5D+=5Bpr=omo=5Ftopspot=5Fprice=5D+=5Bphoto=5Fupdate=5Fprice=5D=5B/math=5D=5B/text=5D= =20>> =20>> (there will be many more fields, but for now I'm just dealing =20>> with those 3) =20>> =20>> If any one of those 3 price variables is not passed from the =20>> form the addition will not happen. =20>> If all 3 are passed they total up just fine. =20>> There might be as many as 13 fields getting totaled up when =20>> complete. =20>> There might be just one price to pass along, maybe 2 or 3 to add =20>> up, maybe 4 or 5 etc =20>> =20>> Adding a =220=22 like mentioned in the talklist entries I've found =20>> does nothing. =20>> =20>> I've used =5Blistvariables=5D and =5Bformvariables=5D to be sure those= 3 =20>> prices are being passed around OK and they are.... =20>> =20>> =20>> Something simple I'm missing or flying over my head=3F =20>> =20>> Adding =5Bhideif=5Ds into that =5Bmath=5D part is an option, but looki=ng =20>> for a simpler solution. =20>> =20>> I'm running version 6.2 on Windows Server2008 =20>> =20>> Searching the newer talklist gets a little clunky at times using =20>> that form..... =20>> =20--53bebfeb_238e1f29_623bContent-Type: text/html; charset="utf-8"Content-Transfer-Encoding: quoted-printableContent-Disposition: inline