Page 1 of 1
Help With Form
Posted: Sat Jun 26, 2010 1:54 pm
by davmor1967
Sorry if this is in the wrong place. I am creating a form for a group insurance company. I am OK on setting up the form, but the wall I have run into is allowing the company person to add multiple employees.
Basically when an employee's information is added then the options are to add another employee or submit the form.
Any help or direction is greatly appreciated.
Re: Help With Form
Posted: Sun Jun 27, 2010 2:24 am
by JakeJ
Without seeing your code it's tough to know where to start.
But it sounds like you need two different submit buttons. One submit button submits the form and moves on to whatever is next, returns home or whatever. The other one submits the data and then reloads the form in order to add another employee.
There are lots of tutorials out there for forms with multiple submit buttons. Go through a couple, give the code a try and then post back if you have a problem.
Re: Help With Form
Posted: Sun Jun 27, 2010 10:45 pm
by davmor1967
What I am basically trying to do is this.
Have person complete contact information (easy enough)
Then, tell the form they want to add employee information. After adding employee 1 information their options would be to submit form or add another employee. After adding another they would have the same options as before, submit or add another. I am sure this can't be as difficult as I assume. I don't really want to send all the info to a database as these forms are a request for a quote and the client doesn't necessarily need to keep the info after the form results are received.
Re: Help With Form
Posted: Sun Jun 27, 2010 11:24 pm
by JakeJ
Where does the information go?
Not that it really matters; I just assumed the info was going to a database.
Make the form action a different page and on that page add code to do what you want.
Code: Select all
//process.php
<?
If ($_POST['submit'] == 'button1'){
//process the form (email data, write to database, whatever)
//redirect to another page (or make a "Submitted Successfully" message or something
}
Else {
//process the form (email data, write to database, whatever)
// go back to the original form so more data can be entered
Does that make sense?
Re: Help With Form
Posted: Mon Jun 28, 2010 8:22 am
by davmor1967
That may do what I need. I will repost with the results. Thanks for the help.
Re: Help With Form
Posted: Mon Jun 28, 2010 12:24 pm
by AbraCadaver
This is very rough but may give you an idea of how to do what I think you're asking in straight PHP:
Code: Select all
if(isset($_POST['submit'])) {
// do processing
// redirect
exit;
}
echo '<form method="post">'
.'contact info <input type="text" name="contact_info"><br>'
.'<input type="submit" name="submit" value="Submit">'
.'<input type="submit" name="add" value="Add Employee"><br>';
$i = 1;
if(isset($_POST['employee'])) {
foreach($_POST['employee'] as $employee) {
if(!empty($employee['first_name']) && !empty($employee['first_name'])) {
echo 'employee '.$i.'<br>'
.'first name <input type="text" name="employee['.$i.'][first_name]" value="'.$employee['first_name'].'"><br>'
.'last name <input type="text" name="employee['.$i.'][last_name]" value="'.$employee['last_name'].'"><br>';
$i++;
}
}
}
if(isset($_POST['add'])) {
echo 'employee '.$i.'<br>'
.'first name <input type="text" name="employee['.$i.'][first_name]"><br>'
.'last name <input type="text" name="employee['.$i.'][last_name]"><br>';
}
echo '</form>';