Page 1 of 1

Forms

Posted: Tue Nov 12, 2002 11:05 am
by whosnotwo
I need some help.
I am making a form and I am curious if this is possible with php.
Every line of the form will have 3 parts. The quantity, part number, and invoice number. Somtimes the user will need to enter in many lines of info (up to 100), sometimes, not many (2 or 3). So I don't want 50 or 100 lines of input boxes showing up if the user is only going to input 2 lines. How would I go about doing this?

Thanks.

Posted: Tue Nov 12, 2002 1:06 pm
by f1nutter
It is possible to create a form in PHP, its just HTML that doesn't need processing. I guess what you are asking is, can PHP be used to vary the number of input boxes needed? Again, yes.

I have filled out forms recently which have maybe 6 input boxes and an option to add more input boxes if I need it.

If your user knows how many input boxes they need, then you might be able to put the input boxes inside a loop, and print out the number needed.

You might want to start by designing forms in basic HTML, and when you are comfortable, add PHP programming. This is the way I work, design everything by hand and spot the patterns, which can be coded in PHP.

Posted: Tue Nov 12, 2002 1:28 pm
by whosnotwo
thanks for the reply.

I have already made my html form. I am just new to php and I am not sure where to start. If you have some suggestions, I would appreciate it.

Posted: Wed Nov 13, 2002 3:46 am
by f1nutter
test_form.php

Code: Select all

<html>
<body>

<form>

<?php

$index = 0;

while($index < 10)
{
  print($index . "<input type=text><br>");

  $index = $index + 1;
}

?>

</form>
</body>
</html>
You should recognise the HTML tags in the above code. I have added a "while" loop (see http://www.php.net/manual/en/control-st ... .while.php) which loops round 10 times, printing the index number and an input box.

Get this working and see what you think.

Is the form you have designed on the web, if so lets have the URL so we can help you more.

Posted: Wed Nov 13, 2002 10:46 am
by m3mn0n
I really see no point in making a form in PHP because it's basically the exact same as HTML other than all the \ you would need to insert to escape the quotations. For handling a form on the other hand, php is needed. ;)

Research: trim()

Posted: Thu Nov 14, 2002 2:18 am
by twigletmac
If you need a dynamic number of form fields then why would you want to code a bunch of pages each with different numbers of form elements. Why also would you want to type (or even sit about copying and pasting) the almost exact same code when PHP could do it quickly for you in a loop? There's no need to worry about escaping quotes either if you, a) use single quotes around your strings, b) use heredoc format, c) escape out of PHP to add the HTML and come back in when you're done.

Mac