Forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
whosnotwo
Forum Newbie
Posts: 2
Joined: Tue Nov 12, 2002 11:05 am

Forms

Post 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.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post 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.
whosnotwo
Forum Newbie
Posts: 2
Joined: Tue Nov 12, 2002 11:05 am

Post 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.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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()
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply