How have 2 PHP Forms on one page.

Help!
I tried looking up coding online and even copied it into my site. The issue I am running into is I have 2 forms, one is a simple contact us form. Name, Email, and Message and you submit it. That form works properly. Below that I have a 2nd form, mainly the same thing but you are able to attach a resume file. When I have clients submit that form, only the name goes through, no message or file. There is also a message on top of the page that says "Perform code for page without POST data. " Below is my code, please help!

[php]<?php

if ($_POST[‘parse_var’] == “contactform”) {

$emailTitle = 'New Email From Your Website!';
$yourEmail = '[email protected]';

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$messageField = $_POST['message'];

$body = <<<EOD





Email: $emailField

Name: $nameField

Message: $messageField

EOD;

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail("$yourEmail", "$emailTitle", "$body", "$headers");

$sent = "Thank You! Your message has been sent.";


if (count($postIdentifierArr) != 1)
{
    count($postIdentifierArr) < 1 or
        die("\$_POST contained more than one post identifier: " .
           implode(" ", $postIdentifierArr));


    die("\$_POST did not contain a known post identifier.");
}
    
switch ($postIdentifierArr[0])
{
case 'F1_Submit':
   echo "Perform actual code for F1_Submit.";
   break;

case 'Modify':
   echo "Perform actual code for F2_Submit.";
   break;
      
case 'Delete':
   echo "Perform actual code for F3_Submit.";
   break;
}

}
else
{
echo "Perform code for page without POST data. ";
}

?>[/php]

[embed=425,349]

Submit this form for more information
about Stellargy Services

        </tr>
        <tr>
          <td colspan="2"><?php print "$sent"; ?></td>
        </tr>
      </table>
    </form></td>
Name:* " />
Email:* "/>
Message:* <?php print "$messagefield"; ?>
 



Submit this form for
job considerations

        </tr>
        <tr>
          <td colspan="2"><?php print "$sent"; ?></td>
        </tr>
      </table>
</form></td>
Name:*
Phone Number:*
Email:*
Position/s for which to be considered:*
Upload your resume:

 
[/embed]

Where and how can I add in contactform2?

Why do you need two forms? Use 1 with an option to upload a file. That does not water it’s own form.

Well the company is requesting to have 2 forms, one just to contact them and the 2nd to submit a resume. I suggested only having one form and they can have the option to submit a resume. But the company insists with 2 separate forms. I thought about creating a separate page, but I was hoping to see if there is a solution to have both.

Using two forms on one page is easy, I do it all the time. As a matter fact I have a login form and a contact form on one page on my current website. To me having the same form for both would be silly. The only important thing to remember is to have different variable names in the two forms (all the variables), so you don’t have any collisions. As for styling it’s up to you, if you don’t care if the two forms look the same then use the same css styling classes.

For example
[php]
if (isset($_POST[‘contact’]) && $_POST[‘contact’] == ‘Submit’ ) {
// Process contact form
}

if (isset($_POST[‘login’]) && $_POST[‘login’] == ‘Login’) {
// Process input form
}
[/php]

As a side note, you probably could use some of the same variables in both forms, but you will have to be careful not to use the sames ones that process the logic. To me it’s easier having separate variable names when it comes to debugging. Sure it might lead to a little more code, but in the long run it will make your life less chaotic when it comes to stomping out errors (Specially logic errors).

One last thing, I notice something in your coding by doing a click glance. Try to keep you PHP and HTML code separate as possible. Usually the PHP processing of the forms goes on the top.

I would just create another form on the page, and instead of sending the data to Services-Contact-Us.php I’d make a new file, like Services-Register-CV.php, or something, and handle the CV-stuff there.

Sponsor our Newsletter | Privacy Policy | Terms of Service