Solved

PHP forms

Posted on 2006-10-26
4
265 Views
Last Modified: 2006-11-18
Hi,

I'm new here and new to PHP and I really need help with a form. Currently I have an html form on a clients website. The form starts with a check box field, then there's a text field for an email address. What follows is a repetition of a series of three text fields:
OwnerName#1
Model#1
Serial#1

OwnerName#2
Model#2
Serial#2

This repeats through #25...it's a very long form

I currently use FormMail to process the form.

Someone told me that by using PHP it would be possible to insert a field before OwnerName#1 that would ask the user to enter the number of Serial# Researches they are requesting. Then using PHP there would be a loop statement that would allow the next page to display just the appropriate number of fields corresponding to the number they entered. So that if they entered 6 the next page would come up with six sets of the three fields shown above as opposed to all 25. Of course the person who told me how "easy" this is could not tell me how to do it.

I posted this in another forum but didn't get much response. Hope I do better here with the experts. This is a definite 500 pointer.

Thanks in advance for any input.

Fred
0
Comment
Question by:fred_belanger
  • 3
4 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17815762
fred_belanger,

Let's say that the field that held this number was named serialNo and used post method in your form.  You could use code like the one below.

for ($i=1; $i<=$_POST['serialNo']; $i++) {
  echo "Owner Name #$i: <input type=\"text\" name=\"ownerName[]\"><br>";
  echo "Model #$i: <input type=\"text\" name=\"model[]\"><br>";
  echo "Serial #$i: <input type=\"text\" name=\"serial[]\"><br>";
}

The name uses square brackets so on the next page PHP will create an array with each value that is entered.  That way all of the values are in one variable, an array.  Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:fred_belanger
ID: 17816045
Thanks for the response b0lsc0tt.

What would I set as the Action on the form at this point? See what I mean about being new to all this?

Right now it looks like this:
<form action="http://www.CompanyName.com/cgi-CompanyName/formmail.cgi" method="POST" onSubmit="MM_validateForm('email','','RisEmail');return document.MM_returnValue" >
                <input type="hidden" name="redirect" value="http://www.CompanyName.com/research_orderB.htm">
                <input type="hidden" name="recipient" value="sales@tCompanyName.com">      

***For client privacy I replaced their info with CompanyName***

I was told I could still use FormMail to process the form but if another way would work better I'm open to suggestions.

Thanks again.

Fred
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 17816305
Fred,

I would write your own script in php.  PHP has a mail function that will send messages or your web hosting provider may have a PHP component that is even better than that function.  There are examples of using the function on EE and you can certainly get help by posting a question.

One big advantage of using your own script is you would not have to include your email address as a hidden field in the form, which exposes it to misuse.  In your script it would be hidden on the server and just available to the server.

Your action attribute would be the page or pages that you are using.  You could do each of these steps with one page (i.e. big, long script with multiple parts) or have a different page for each part (i.e. page1.php, page2.php, submit.php).  The action is the page where the form is submitted.

Let me know if you have any questions or need more information.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17816583
I'm glad that I could help you.  Thank you for the grade, the points and the fun question.  Enjoy learning and using PHP.  It's great!

bol
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now