PHP Form Generator? Such a thing?

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

jmilane
Forum Commoner
Posts: 89
Joined: Mon Aug 07, 2006 6:05 pm

PHP Form Generator? Such a thing?

Post by jmilane »

Hello,

I am trying to write a PHP script that will take fields and insert them into a database, then send off an email depending on what boxes are checked. Pretty standard stuff. Nothing particularly extraordinary.

Problem is, I dont know PHP very well at all. I can kind of sort of read it, but I cant write it by hand. The other problem is, I need to write several of these very soon and have no resources. We are a small nonprofit, and I am the tech department... more or less.

I have seen several PHP form generators on sourceforge, but the ones I downloaded did not work.

The idea of a PHP form generator is very appealing to me right now.

If anyone knows of one that works and can do what I need it to, or knows another way I can attack this head-on, I would be very appreciative if you would let me know. I am usually on ICQ, and I am happy to get your emails. I am also planning on being around here quite a bit more now that I am in this position and need to learn.

Thank you for taking the time to consider my request.

Take care.

J
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

How many forms are you needing? How large are the forms?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Never used it... but I've been recommended this a few times: http://pear.php.net/package/HTML_QuickForm/
jmilane
Forum Commoner
Posts: 89
Joined: Mon Aug 07, 2006 6:05 pm

Post by jmilane »

hawleyjr wrote:How many forms are you needing? How large are the forms?
I only need one form to start.

It is a registration form that collects peoples' address, phone number, age, etc. I guess there are about 15 fields in total, and they all need to be validated. Only about two are not required.

It also asks what programs they are interested in and depending on which are checked off, sends off an email to the corresponding staff member.

I actually completed a form that does this with the aid of FacileForms for Mambo, but now this is going to have to be free-floating, called from a Mambo page but updating a seperate database.

J
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

jmilane wrote:
hawleyjr wrote:How many forms are you needing? How large are the forms?
I only need one form to start.

It is a registration form that collects peoples' address, phone number, age, etc. I guess there are about 15 fields in total, and they all need to be validated. Only about two are not required.

It also asks what programs they are interested in and depending on which are checked off, sends off an email to the corresponding staff member.

I actually completed a form that does this with the aid of FacileForms for Mambo, but now this is going to have to be free-floating, called from a Mambo page but updating a seperate database.

J
Sounds like a fairly small project. I’m sure there are many member here who could do it for a small fee.
jmilane
Forum Commoner
Posts: 89
Joined: Mon Aug 07, 2006 6:05 pm

Post by jmilane »

hawleyjr wrote:
jmilane wrote:
hawleyjr wrote:How many forms are you needing? How large are the forms?
I only need one form to start.

It is a registration form that collects peoples' address, phone number, age, etc. I guess there are about 15 fields in total, and they all need to be validated. Only about two are not required.

It also asks what programs they are interested in and depending on which are checked off, sends off an email to the corresponding staff member.

I actually completed a form that does this with the aid of FacileForms for Mambo, but now this is going to have to be free-floating, called from a Mambo page but updating a seperate database.

J
Sounds like a fairly small project. I’m sure there are many member here who could do it for a small fee.
Like I said, I want to do it myself... I work for a nonprofit... ie - we dont have no money.

Not looking for a handout... just a tool I can use to make life easier.

J
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Not a small project at all. These things are mammoth in complexity. I think Mark (Pimptastic) once wrote a basic form2sql2form class in Code Snippets on the forum.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

d11wtq wrote:Not a small project at all. These things are mammoth in complexity. I think Mark (Pimptastic) once wrote a basic form2sql2form class in Code Snippets on the forum.
I was talking about creating a singled out form ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

jmilane - So you're talking about making an HTML form that sends data to a PHP page? And that PHP page inserts data into a database and emails someone based in what was selected in the form? Please confirm that this is what you are looking to do. If this is what you want, that is rather simple. If you are looking for an app that makes your forms, and does what you want it to do, that is quite a bit more involved.
jmilane
Forum Commoner
Posts: 89
Joined: Mon Aug 07, 2006 6:05 pm

Post by jmilane »

Everah wrote:jmilane - So you're talking about making an HTML form that sends data to a PHP page? And that PHP page inserts data into a database and emails someone based in what was selected in the form? Please confirm that this is what you are looking to do. If this is what you want, that is rather simple. If you are looking for an app that makes your forms, and does what you want it to do, that is quite a bit more involved.
Yes, all I want is a registration form. People will click "Register Now!" and be presented with a simple form.

They will then register for one or more programs. They will enter their name and all their personal information and pick any combination of program A, B, C, or D.

They will hit, "Submit"

Their personal info will go to the database.

The fields will also be parsed into the $body (just concatenating a long string) of an email and sent to whomever is the head of the program(s) they selected. The email will be very basic:

Bob Jones has registered.
He was born in 12/12/1994
He was referred by John Smith
He is male.
Etc...


I dont think it is complicated. For me, sure... I cant do it at all. But I dont think in the scope of PHP that it is a big deal.

Id appreciate it if anyone could tell me about a PHP Form Generator that works. I have downloaded a few, but they are broken and dont work properly.

Or, maybe I am silly to expect to be able to do this without more knowledge of programming. I used to code in VB and PowerBuilder (and SQL) but that was 10 years ago. I was overseas for several years, and am getting back into technology. Sorry if my questions are dumb. I just dont like to have people do stuff for me without learning what it is that they are doing... so I dont have to ask next time.

Besides, I like this stuff so far. Just cant deliver what Boss wants with my current knowledge base.

J
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Honestly, based on what you just posted, you don't need a form generator. You need to develop a simple HTML form on your own, then develop the PHP script to handle the passed information. It is really not that difficult (if you want to do it on your own) but it may take a little bit of refresher training for you.

I would recommend picking up a couple of books/tutorials on beginning PHP. Most everything you will need (save for data validation) will be in a beginners guide to PHP. Or, you can try some things on your own, post here with challenges/problems, and together we can help solve your issues.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

milane wrote:Like I said, I want to do it myself... I work for a nonprofit... ie - we dont have no money.

Not looking for a handout... just a tool I can use to make life easier.
Forms processing is just complex enough that it is difficult for beginners to do, and difficult for experienced programmers to generalize (or at least agree on how to do it).

That said the basics are pretty simple. First you need a HTML form, which starts with a form tag that specifies the page that the form will be submitted to and the method (GET or POST). It looks like this:

Code: Select all

<form action="myformpage.php" method="post">
Then there are form fields. There are a couple of different kinds. The basic text input looks like this with a name and a value (which is empty in this example):

Code: Select all

<input type="text" name="first_name" value=""/>
Then a button to submit the form:

Code: Select all

<input type="submit" name="submit" value="Go"/>
And finally you need to close the form with the tag:

Code: Select all

</form>
I am going the add a error message which will come from the PHP script below. The whole thing looks like this (put it in a file named myformtemplate.php):

Code: Select all

<span style="color:red"><?php echo implode('', $errors); ?></span>
<form action="myformpage.php" method="post">
<input type="text" name="first_name" value=""/>
<input type="submit" name="submit" value="Go"/>
</form>
OK, so that's the HTML part. Now you need the PHP script to manage the form. One way to do it goes something like this:

1. Get the values from the $_POST superglobal array.
2. Filter the values to make sure there are no unwanted characters
3. Check that required values exist and are valid
4. If there are errors then display the form
5. If there are no errors then redirect to the next page (this prevents resubmits).

So the PHP code would looks something like this (put this code in the file myform.php):

Code: Select all

// filter the value from the form to only all letters and space
$first_name = preg_replace('/[^a-zA-Z\ ]/', '', $_POST['last_name']);

// check the name based on some rules and set errors if there are problems
$errors = array();
if ($first_name == '') {
    $errors[] = 'Please enter a first name. ';
} elseif (strlen($first_name) < 3) {
    $errors[] = 'The first name must be at least three letters long. ';
}

// check if the form is valid
if ($errors) {
    // show the form if there are errors
    include 'myformtemplate.php';
} else {
    // do and other processing here, such as saving to a database or emailing
    mail('me@mysite.com', 'Form Message', "A message from $first_name");

    // redirect to another page if all required fields are acceptable
    header('Location: http://www.mysite.com/mynextpage.php');
}
To test it go to http://www.mysite.com/myform.php

There are some other things to add like checking for submit and not showing error messages the first time the page is displayed ... but that's the basics.

EDIT - fixed (strlen($first_name) < 3) per Everah
Last edited by Christopher on Tue Aug 08, 2006 2:40 am, edited 2 times in total.
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Don't you want the name check to be at least three chars long? This

Code: Select all

strlen($first_name) >= 3
should be

Code: Select all

strlen($first_name) < 3
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

The Ninja Space Goat wrote:Never used it... but I've been recommended this a few times: http://pear.php.net/package/HTML_QuickForm/
Just tried this out... it's very nice. You need a little OOP experience though. It pretty simple and well documented, so really it should not be that hard to learn though. I recommend it.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

d11wtq wrote:Not a small project at all. These things are mammoth in complexity. I think Mark (Pimptastic) once wrote a basic form2sql2form class in Code Snippets on the forum.
Yep...very very basic...but it sufficed for my needs at the time

It can be found here - viewtopic.php?t=30683&highlight=


Burrito also did something similar which can be found here - viewtopic.php?t=40588&highlight=
Post Reply