-
Validate textfields before submit
Hi. I have this form and I want it to display "*required field" beside the textfield if it is blank. If the Submit button is clicked but there are blank fields, it should not submit. Do you mind showing me how?
I don't know where to put the validations. This swf is put in a php page so here's some part of it
Code:
var fllname:TextField;
var address:TextField;
var ContactNo:TextField;
var quantity:TextField;
var otrack:TextField;
btnSubmit1.addEventListener(MouseEvent.CLICK, submit);
function submit(e:MouseEvent):void{
var urlvars: URLVariables = new URLVariables;
urlvars.fllname = fllname.text;
urlvars.Oadd = address.text;
urlvars.ContactNo = ContactNo.text;
urlvars.oquantiy = quantity.text;
urlvars.otrack = otrack.text;
urlvars.cake = txtCake.text;
urlvars.frosting = txtFrosting.text;
urlvars.topping = txtToppings.text;
urlvars.topping2 = txtToppings2.text;
urlvars.filling = txtFilling.text;
urlvars.amt = lblAmount.text;
var urlreq:URLRequest = new URLRequest("http://localhost/MCC/order.php");
urlreq.method = URLRequestMethod.POST;
urlreq.data = urlvars;
var loader : URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq);
nextFrame();
}
-
which fields would you like to be required?
-
These
fllname:TextField;
address:TextField;
ContactNo:TextField;
quantity:TextField;
-
.
Hi,
With the code you have you can do a simple check on each field, I havent filled in all of them , I will let you decide which method you prefer. length or ==
PHP Code:
btnSubmit1.addEventListener(MouseEvent.CLICK, doCheck);
function doCheck(e:MouseEvent):void
{
if (fllname.text == "")
{
trace("Need box 1");
}
else if (address.text.length < 1)
{
trace("Need box 2");
}
else if (ContactNo.text)
{
trace("Need box 3");
}
else if (quantity.text)
{
trace("Need box 4");
}
else if (otrack.text)
{
trace("Need box 5");
}
else if (txtCake.text)
{
trace("Need box 6");
}
else if (txtFrosting.text)
{
trace("Need box 7");
}
else if (txtToppings.text)
{
trace("Need box 8");
}
else if (txtToppings2.text)
{
trace("Need box 9");
}
else if (txtFilling.text)
{
trace("Need box 10");
}
else if (lblAmount.text)
{
trace("Need box 11");
}
else
{
trace("All OK");
submit();
}
}
function submit():void
{
var urlvars:URLVariables = new URLVariables();
urlvars.fllname = fllname.text;
urlvars.Oadd = address.text;
urlvars.ContactNo = ContactNo.text;
urlvars.oquantiy = quantity.text;
urlvars.otrack = otrack.text;
urlvars.cake = txtCake.text;
urlvars.frosting = txtFrosting.text;
urlvars.topping = txtToppings.text;
urlvars.topping2 = txtToppings2.text;
urlvars.filling = txtFilling.text;
urlvars.amt = lblAmount.text;
var urlreq:URLRequest = new URLRequest("http://localhost/MCC/order.php");
urlreq.method = URLRequestMethod.POST;
urlreq.data = urlvars;
var loader:URLLoader = new URLLoader ;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq);
nextFrame();
}
-
Hi...
It's giving me this error
1136: Incorrect number of arguments. Expected 1.
it highlights the line of submit();
-
.
well post your whole code or attach the fla (second one better0
actually remove whatever is inside of the brackets on submit function
-
-
.
you didnt put any of the check code in it.
put the code in so we get thte error you said you have then we can fix that error
-
Oh yeah. I removed what's inside the submit function. It worked now but I want the "Need box __" to appear beside the field.
-
I'm editing now. sorry for that.
What's the difference between length and the other one?
-
.
Hi,
Length means the textfield letter amount and == means is it equal to
-
I see. Thanks.How to display the "Need..." beside the field?
-
.
-
-
.
Hi,
Scene 1, Layer 'AS', Frame 1, Line 10 1120: Access of undefined property cakeSelected.
Scene 1, Layer 'AS', Frame 1, Line 11 1120: Access of undefined property frostingSelected.
Scene 1, Layer 'AS', Frame 1, Line 12 1120: Access of undefined property toppingsSelected.
Scene 1, Layer 'AS', Frame 1, Line 13 1120: Access of undefined property toppings2Selected.
Scene 1, Layer 'AS', Frame 1, Line 14 1120: Access of undefined property fillingSelected.
you need to fix those errors first
you seem to have other code in your files that you do not tell us about in the first place, it could save time for both of us.
Yo also seem to not post the whole file, is it a puzzle?
Last edited by fruitbeard; 01-22-2015 at 09:13 AM.
-
oh. I sent you the frame for the scene i just need. You can disregard those.
-
.
Hi
with the code from the file you sent, I havent changed anything other than to comment out what i need to prevent errors.
PHP Code:
stop();
import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.events.TextEvent;
var sCake:String// = cakeSelected; var sFrosting:String// = frostingSelected; var sToppings:String// = toppingsSelected; var sToppings2:String// = toppings2Selected; var sFilling:String// = fillingSelected;
var bCakeInt:int; var bFrostingInt:int; var bToppingsInt:int; var bToppings2Int:int; var bFellingInt:int;
var fllName:String; var addressO:String; var contactNO:String; var quantityO:String; var tracking:String; var amtStr:String;
//var fllname:TextField; //var address:TextField; //var ContactNo:TextField; //var quantity:TextField; //var otrack:TextField;
stage.focus = fllname; ContactNo.maxChars = 12; fllname.multiline = false; address.multiline = false; ContactNo.multiline = false; quantity.multiline = false;
fllname.text = ""; address.text = ""; ContactNo.text = ""; quantity.text = "";
fllname.restrict = "^0-9"; quantity.restrict = "1-9"; ContactNo.restrict = "0-9";
reqField.text = "";
function generateRandomString(strlen:Number):String { var chars:String = "bcdefghijklmnpqrstvwxyzABCDEFGHIJKLMNPQRSTVWXYZ123456789"; var num_chars:Number = chars.length - 1; var randomChar:String = "";
for (var i:Number = 0; i < strlen; i++) { randomChar += chars.charAt(Math.floor(Math.random() * num_chars)); } return randomChar; }
otrack.text = String(generateRandomString(8));
quantity.restrict = "0-9";
/* if (fllName != null) { fllname.text = String(fllName); } else { fllName = ""; }
if (addressO != null) { address.text = String(addressO); } else { addressO = ""; }
if (contactNO != null) { ContactNo.text = String(contactNO); } else { contactNO = ""; }
if (quantityO != null) { quantity.text = String(quantityO); if (amtStr != null) { lblAmount.text = amtStr; } } else { quantityO = ""; }
if (tracking != null) { otrack.text = String(tracking); } else { tracking = ""; } */
// Switch case for cakes switch (sCake) { case "bChoco" : txtCake.text = "Chocolate"; bCakeInt = 0; break; case "bVanilla" : txtCake.text = "Vanilla"; bCakeInt = 1; break; case "bMocha" : txtCake.text = "Mocha"; bCakeInt = 2; break; case "bCaramel" : txtCake.text = "Caramel"; bCakeInt = 3; break; default : txtCake.text = "Chocolate"; bCakeInt = 0; break; }
// Switch case for frosting switch (sFrosting) { case "fChoco" : txtFrosting.text = "Chocolate"; bFrostingInt = 0; break; case "fVanilla" : txtFrosting.text = "Vanilla"; bFrostingInt = 1; break; case "fBubblegum" : txtFrosting.text = "Bubble gum"; bFrostingInt = 2; break; case "fStrawberry" : txtFrosting.text = "Strawberry"; bFrostingInt = 3; break; default : txtFrosting.text = "Chocolate"; bFrostingInt = 0; break; }
// Switch case for Toppings 1 switch (sToppings) { case "tChoco" : txtToppings.text = "Choco Shavings"; bToppingsInt = 0; break; case "tWhiteChoco" : txtToppings.text = "White Choco Shavings"; bToppingsInt = 1; break; case "tBlackNWhite" : txtToppings.text = "Black and white"; bToppingsInt = 2; break; case "tChili" : txtToppings.text = "Chili"; bToppingsInt = 3; break; case "tNone" : txtToppings.text = "None"; bToppingsInt = 4; break; default : txtToppings.text = "Choco Shavings"; bToppingsInt = 0; break; }
// Switch case for Toppings 2 switch (sToppings2) { case "ttChoco" : txtToppings2.text = "Choco Shavings"; bToppings2Int = 0; break; case "ttWhiteChoco" : txtToppings2.text = "White Choco Shavings"; bToppings2Int = 1; break; case "ttBlackNWhite" : txtToppings2.text = "Black and white"; bToppings2Int = 2; break; case "ttChili" : txtToppings2.text = "Chili"; bToppings2Int = 3; break; case "ttNone" : txtToppings2.text = "None"; bToppings2Int = 4; break; default : txtToppings2.text = "Choco Shavings"; bToppings2Int = 0; break; }
// Switch case for Filling switch (sFilling) { case "fillChoco" : txtFilling.text = "Chocolate"; bFellingInt = 0; break; case "fillStrawberryjam" : txtFilling.text = "Strawberry Jam"; bFellingInt = 1; break; case "fillBlueberry" : txtFilling.text = "Blueberry"; bFellingInt = 2; break; case "fillNofilling" : txtFilling.text = "None"; bFellingInt = 3; break; default : txtFilling.text = "Chocolate"; bFellingInt = 0; break; }
var bCInt:int; var bFrInt:int; var bTInt:int; var bToInt:int; var bFeInt:int;
quantity.addEventListener(Event.CHANGE, changeListener, false, 0, true); var totalAmt:int; function changeListener(e:Event):void {
var withFelling:int = 55; var withoutFelling:int = 50;
if (txtFilling.text == "None") {
totalAmt = withoutFelling * int(quantity.text); } else { totalAmt = withFelling * int(quantity.text); }
lblAmount.text = String(totalAmt);
}
btnBack.addEventListener(MouseEvent.CLICK, backrward);
function backrward(event:MouseEvent) { bCInt = bCakeInt; bFrInt = bFrostingInt; bTInt = bToppingsInt; bToInt = bToppings2Int; bFeInt = bFellingInt; fllName = fllname.text; addressO = address.text; contactNO = ContactNo.text; quantityO = quantity.text; tracking = otrack.text; amtStr = lblAmount.text; prevFrame(); }
btnSubmit1.addEventListener(MouseEvent.CLICK, doCheck);
function doCheck(e:MouseEvent):void { reqField.text = ""; if (fllname.text == "") { trace("Need box 1"); reqField.text = "Need box 1"; } else if (address.text.length < 1) { trace("Need box 2"); reqField.text = "Need box 2"; } else if (ContactNo.text == "") { trace("Need box 3"); reqField.text = "Need box 3"; } else if (quantity.text == "") { trace("Need box 4"); reqField.text = "Need box 4"; } else { trace("All OK"); reqField.text = ""; submit(); } }
function submit():void { var urlvars:URLVariables = new URLVariables();
urlvars.fllname = fllname.text; urlvars.Oadd = address.text; urlvars.ContactNo = ContactNo.text; urlvars.oquantiy = quantity.text; urlvars.otrack = otrack.text; urlvars.cake = txtCake.text; urlvars.frosting = txtFrosting.text; urlvars.topping = txtToppings.text; urlvars.topping2 = txtToppings2.text; urlvars.filling = txtFilling.text; urlvars.amt = lblAmount.text;
var urlreq:URLRequest = new URLRequest("http://localhost/MCC/order.php"); urlreq.method = URLRequestMethod.POST; urlreq.data = urlvars;
var loader:URLLoader = new URLLoader ; loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq); nextFrame();
}
i'm sure you can figure out what goes where
I did remover one error textfield and just use one error Textfield at the top called reqField, one text box for each and every error as it happens
Last edited by fruitbeard; 01-22-2015 at 09:35 AM.
-
Works fine but just one thing. I just changes what's inside the "__" to "All fields required"...I don't know why it doesn't show all the letters.
jj.png
-
I changed the Classic text to TLF text and it displayed every letter. Thank you so much
-
.
Hi,
I'm not sure you needed the change all text to tlf text, however you did have a mixtrue of device fonts and anti-alias for animation fonts,
i personally prefer to use anti-alias for readability (looks better).
It always helps to embed fonts when you use dynamic or input textfields
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|