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.
Forms
Moderator: General Moderators
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.
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.
test_form.php
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.
Code: Select all
<html>
<body>
<form>
<?php
$index = 0;
while($index < 10)
{
print($index . "<input type=text><br>");
$index = $index + 1;
}
?>
</form>
</body>
</html>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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
Mac