Form help: Syntax & Logic


Posted on 16th Feb 2014 07:03 pm by admin

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...

Code: <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...

Code: $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...
Code: for ($X=1;$X < sizeof($glass1)-1; $X++) {
// how's the syntax on the next line???
if($_POST['Qty'.$X]!=NULL ){
$glasspart1.="Part $Xn";
//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!!

No comments posted yet

Your Answer:

Login to answer
98 Like 50 Dislike
Previous forums Next forums
Other forums

PHP not creating file.
Its supposed to create a .ini file in the /scriptfiles/users/ with the name they entered into the fi

Can't shake the "Warning: include()" error
I've just uploaded my site to a new server and where I have PHP include tags in my HTML, the browser

$GPRMC and NMEA how to extract from report
Hi There,

Im a little bi lost and not sure where to start with this one, ive got a small gps

simple ping code
been searchin the site/web and found code thats simple but doesnt work.

I have a personal we

Help adding strtolower( to my in_array
strtolower i need to add it to this to work, iuno how.

Code: $moderators = array('Admin', 'ba

Alternate messaging
I have 4 strings in MySQL db1

$string1 : Hello
$string2 : Hi
$string3 : Great
$strin

$_GET problem
Hi all,

Have a bit of a problem with a little piece of code, I am not sure if this should be

iMatch stored value with the current value in a loop
Hello,

I have a MySQL db were I store articles in.

I have a form to fill these article

if statements problems
Hi. I'm trying to make a web form, but I kind of hit a dead end trying to figure out why it doesn't

Get relative path from absolute path
How would one go about getting the relative path to a file from its absolute path?

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash