Jump to content

Help with Form


Recommended Posts

On one of my pages I have 2 forms. I use  if ($_POST) { to activate the form. The problem is that both forms submit when either of the forms are submitted. Is there any way I can make it so that each form is triggered seperately? You can see what I mean at: [url=http://www.wemustdesign.com/contact.php]http://www.wemustdesign.com/contact.php[/url]

[code]
<?php

        if ($_POST)
        {
            $contact_name = $_POST['contact_name'];
            $contact_mail = $_POST['contact_mail'];
$contact_phone = $_POST['contact_phone'];
$contact_enquiry = $_POST['contact_enquiry'];
         


            $message = "Message from $contact_name \n\nE-Mail:$contact_mail\n\n$contact_phone \n\nTelephone:\n\n$contact_phone\n\nEnquiry:\n\n$contact_enquiry";

           
            mail("[email protected]", "Contact Form Submitted", $message);
           
            echo "
<fieldset>
<legend>Enquiry Form Submitted</legend>
<br />
<span class='required'>Thankyou for your enquiry. I will get back to you as soon as possible.</span>
<br />
- Chris Davidson
<br />
<br />
</fieldset>"
;

        }
        else
        {
  $ledgend = "Enquiry Form <span class= 'required'>(Required *)</span> ";
     
?>

  <form name="" method="post" action="<?= $PHP_SELF ?>">
  <fieldset>
  <legend><? echo "$ledgend" ?></legend>
<br />

<label for="contact_name">Name <span class= "required">*</span></label>
<input type="text" value="" name="contact_name"  id="contact_name"/>
<br />

<label for="contact_mail">Email Address <span class= "required">*</span></label>
<input type="text"  value="" name="contact_mail"  id="contact_mail"/>
<br />

<label for="contact_phone">Telephone:</label>
<input type="text"  value="" name="contact_phone"  id="contact_phone"/><br />

<label for="contact_enquiry">Enquiry <span class= "required">*</span></label>
<textarea name="contact_enquiry"  id="contact_enquiry"></textarea><br />
<br />
    <input type="submit" title="Submit callback request" class="btn" onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" name="Submit" value="Submit" />
</fieldset>
  </form>
          <?php

        }

        ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15304-help-with-form/
Share on other sites

[quote author=localhost link=topic=101439.msg401513#msg401513 date=1153531132]
if(isset($_POST['Submit']))
{
[/quote]

The reson that this works is because instead of checking for something that should always be there, you are checking if the submit button has been pressed.

edit: what i mean by this, to be more clear is,
$_POST is there. Period.
$_POST['Submit'] is only there if the submit button has been pressed.
Thus, checking for $_POST is useless.
Link to comment
https://forums.phpfreaks.com/topic/15304-help-with-form/#findComment-61927
Share on other sites

Another way to do this is to give the submit buttons two different names.

This short script illustrates this:
[code]<?php
if (isset($_POST['submit']) || isset($_POST['submit1'])) echo '<pre>' . print_r($_POST,true) . '</pre>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>two forms</title>
</head>
<body>
<form method="post">
<input type="hidden" name="inform" value="1">
<input type="submit" name="submit" value="Send Form 1">
</form>
<br>
<form method="post">
<input type="hidden" name="inform" value="2">
<input type="submit" name="submit" value="Send Form 2">
</form>
</body>
</html>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/15304-help-with-form/#findComment-62077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.