MainStWebGuy Posted October 9, 2009 Share Posted October 9, 2009 Hello again all, I'm working on a form and ran into a wall (again) and can't seem to think through how to best code what i need (the logic side). I've begun by just sitting down and starting to code with the little knowledge i have of php but can't seem to get it right and am not sure i'm using the correct syntax... The form is your basic contact form that collects contact information, but it also has a place for customers to input product information such as a quantity and dimensions (width and height). The form offers the visitor a chance to enter up to 7 different "products" and their quantity, width, and height.... here's that part of the form... <form name="myForm" action="<?php echo $_SERVER['PHP_SELF ']; ?>" method="POST"> <table width="600" cellspacing="2" cellpadding="1"> <tr> <td>Quantity</td> <td>Width</td> <td>height</td> </tr> <tr> <td><input type="text" name="qty1" /></td> <td><input type="text" name="width1" /></td> <td><input type="text" name="height1" /></td> </tr> <tr> <td><input type="text" name="qty2" /></td> <td><input type="text" name="width2" /></td> <td><input type="text" name="height2" /></td> </tr> <tr> <td><input type="text" name="qty3" /></td> <td><input type="text" name="width3" /></td> <td><input type="text" name="height3" /></td> </tr> <tr> <td><input type="text" name="qty4" /></td> <td><input type="text" name="width4" /></td> <td><input type="text" name="height4" /></td> </tr> <tr> <td><input type="text" name="qty5" /></td> <td><input type="text" name="width5" /></td> <td><input type="text" name="height5" /></td> </tr> <tr> <td><input type="text" name="qty6" /></td> <td><input type="text" name="width6" /></td> <td><input type="text" name="height6" /></td> </tr> <tr> <td><input type="text" name="qty7" /></td> <td><input type="text" name="width7" /></td> <td><input type="text" name="height7" /></td> </tr> </table> </form> ... pretty simple stuff there... I am having trouble though collecting the info from the form... the newbie in me (to php and programming in general) had me begin hard coding each variable like this... $qty1 = $_POST['qty1']; $qty2 = $_POST['qty2']; .... $width1 = $_POST['qty1']; $width2 = $_POST['qty2']; .... $height1 = $_POST['qty1']; $height2 = $_POST['qty2']; .... I thought that it might make more sense (and help me learn a little) to try and use a loop to create these variables.... is this good practice? Here's what i came up with... for ($X=1;$X < sizeof($glass1)-1; $X++) { // how's the syntax on the next line??? if($_POST['Qty'.$X]!=NULL ){ $glasspart1.="Part $X\n"; //below: can i use $qty$X like that? $glass1 = array("QTY: $qty$X", "DIMENSIONS: $width$X X $height$X"); $glasspart1.= "$glass1[$X-1]\n"; } } am i on the right track so far? I still am having trouble validating the form (the logic) in order to only create arrays for the parts (1-7) that were filled in, but i can save that for another post :-) thanks again all for any help or advice!! J Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/ Share on other sites More sharing options...
kickstart Posted October 9, 2009 Share Posted October 9, 2009 Hi If you want to do it like that then you need the other fields back as well:- $glass1 = array("QTY: ".$_POST['Qty'.$X], "DIMENSIONS: ".$_POST['Width'.$X]." ".$_POST['Height'.$X]); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/#findComment-933919 Share on other sites More sharing options...
MainStWebGuy Posted October 12, 2009 Author Share Posted October 12, 2009 Thanks for a point in the right direction, but i'm still having some issues. The form is processing the info to itself, but when i try to echo out the parts(and properties) that have been inputted, they are coming up blank.... I've attached the code i'm working with with your suggestions added as well as some other little things i've tried to see if they would help get it working. I LOVE input, the good the bad and the ugly, so feel free to call it out when you see something that's stupid, newb-ish, etc! :-) thanks again, J [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/#findComment-935546 Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 Redesign your form so that it uses arrays: <tr> <td><input type="text" name="qty[]" /></td> <td><input type="text" name="width[]" /></td> <td><input type="text" name="height[]" /></td> </tr> Then you can use arrays more easily in your back-end code $qty[1] = $_POST['qty'][1]; Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/#findComment-935552 Share on other sites More sharing options...
MainStWebGuy Posted October 12, 2009 Author Share Posted October 12, 2009 That makes a lot of sense (to me i think) and seems to simplify the code a bit. Thanks! However, I'm still having the same issue... the form process, but outputs nothing. The new attachment contains the updated code... Is this what you were talking about? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/#findComment-935583 Share on other sites More sharing options...
MainStWebGuy Posted October 14, 2009 Author Share Posted October 14, 2009 Still can't get this thing going... can anyone shed some light on this at all? thanks again in advance! J Quote Link to comment https://forums.phpfreaks.com/topic/177123-form-help-syntax-logic/#findComment-936719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.