Jump to content

form doesn't submit to self?


croakingtoad

Recommended Posts

I have the following code and am trying to get the form to submit to itself but when you submit the form, it reloads the page but doesn't execute the first if() statement...not sure what I'm doing wrong.  It just reloads the page...

Any help appreciated!

[code]
if (isset($email)) {

$subject = "Contact from Firefly website";
$headers = "From: $firstName $lastName <$email>";

$to = $to . "@fireflylighting.com";

$message = "Email from:" . "\r\n";
$message .= "$firstName $lastName" . "\r\n";
$message .= "$title" . "\r\n";
$message .= "$company" . "\r\n";
$message .= "$phone" . "\r\n";
$message .= "$email" . "\r\n" . "\r\n";
$message .= "Message:" . "\r\n";
$message .= "$mess";

/* mail($to, $subject, $message, $headers); */
echo "$to<br />$headers<br /><br />$message";

echo '<h3>Thank you!</h3> <p>Your message has been sent.  Someone will contact you within 2 business days.</p>';

} else {

echo "<form action="index.php?id=6" method=\"post\">";
echo '
<label>Send message to:</label> <select name="to">
<option value="">Select a Recipient</option>
<option value="sales">Sales</option>
<option value="engineering">Engineering</option>
<option value="marketing">Marketing</option>
<option value="service">Customer Service</option>
</select><br />
<br />
<input type="text" name="firstName" size="20" /> <label>First Name</label><br />
<input type="text" name="lastName" size="20" /> <label>Last Name</label><br />
<br />
<input type="text" name="title" size="20" /> <label>Title</label><br />
<input type="text" name="company" size="20" /> <label>Company Name</label><br />
<input type="text" name="phone" size="20" /> <label>Phone Number</label><br />
<input type="text" name="email" size="20" /> <label>Email Address</label><br />
<br />
<textarea name="mess" rows="10" cols="20">Please use this area to type your message.</textarea>

<input type="submit" value="Send Message" name="submit" />

</form>';

}
[/code]
Link to comment
Share on other sites

[quote author=spfoonnewb link=topic=118340.msg483489#msg483489 date=1165949967]
Put

[code]$email = $_POST['email'];[/code]

Above that code. (Like right under the <?php)
[/quote]

What I mean is a way to take every $_POST[] var and change it to just a standard php var like $var instead of $_POST['var'].  But do it to all of them at once without having to manually set every one..?
Link to comment
Share on other sites

I'm still having the same issue...here's what I have now.  When I submit the form the if() isn't getting picked up...

[code]
if (isset($_POST['submit'])) {

extract($_POST);

$subject = "Contact from Firefly website";
$headers = "From: $firstName $lastName <$email>";

$to = $to . "@fireflylightinginnovations.com";

$message = "Email from:" . "\r\n";
$message .= "$firstName $lastName" . "\r\n";
$message .= "$title" . "\r\n";
$message .= "$company" . "\r\n";
$message .= "$phone" . "\r\n";
$message .= "$email" . "\r\n" . "\r\n";
$message .= "Message:" . "\r\n";
$message .= "$mess";

/* mail($to, $subject, $message, $headers); */
echo "$to<br />$headers<br /><br />$message";

echo '<h3>Thank you!</h3> <p>Your message has been sent.  Someone will contact you within 2 business days.</p>';

} else {

echo "<form action=\"index.php?id=6\" method=\"post\">";
echo '
<label>Send message to:</label> <select name="to">
<option value="">Select a Recipient</option>
<option value="sales">Sales</option>
<option value="engineering">Engineering</option>
<option value="marketing">Marketing</option>
<option value="service">Customer Service</option>
</select><br />
<br />
<input type="text" name="firstName" size="20" /> <label>First Name</label><br />
<input type="text" name="lastName" size="20" /> <label>Last Name</label><br />
<br />
<input type="text" name="title" size="20" /> <label>Title</label><br />
<input type="text" name="company" size="20" /> <label>Company Name</label><br />
<input type="text" name="phone" size="20" /> <label>Phone Number</label><br />
<input type="text" name="email" size="20" /> <label>Email Address</label><br />
<br />
<textarea name="mess" rows="10" cols="20">Please use this area to type your message.</textarea>

<input type="submit" value="Send Message" name="submit" />

</form>';

}
[/code]

I just added a line into the else section that displays the form to echo out a couple of the $vars and nothing is showing up there either after submit....any ideas what I'm doing wrong?
Link to comment
Share on other sites

Why do you need the id. Making the action the way you have it will not work with $_POST['id']. You need to add a hidden input for a POST form.
[code]echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
echo "<input type=hidden name=id value=6>";[/code]

Now your id will be passed in a POST variable

I am guessing that this page is called index.php. maybe change it to what I have above. That way you can rename your page to whatever you like and your script will still work.

[code]<?php
if (isset($_POST['submit'])) {

extract($_POST);

$subject = "Contact from Firefly website";
$headers = "From: $firstName $lastName <$email>";

$to = $to . "@fireflylightinginnovations.com";

$message = "Email from:" . "\r\n";
$message .= "$firstName $lastName" . "\r\n";
$message .= "$title" . "\r\n";
$message .= "$company" . "\r\n";
$message .= "$phone" . "\r\n";
$message .= "$email" . "\r\n" . "\r\n";
$message .= "Message:" . "\r\n";
$message .= "$mess";

/* mail($to, $subject, $message, $headers); */
echo "$to<br />$headers<br /><br />$message";

echo '<h3>Thank you!</h3> <p>Your message has been sent.  Someone will contact you within 2 business days.</p>';

} else {

echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
echo '
<label>Send message to:</label> <select name="to">
<option value="">Select a Recipient</option>
<option value="sales">Sales</option>
<option value="engineering">Engineering</option>
<option value="marketing">Marketing</option>
<option value="service">Customer Service</option>
</select><br />
<br />
<input type="text" name="firstName" size="20" /> <label>First Name</label><br />
<input type="text" name="lastName" size="20" /> <label>Last Name</label><br />
<br />
<input type="text" name="title" size="20" /> <label>Title</label><br />
<input type="text" name="company" size="20" /> <label>Company Name</label><br />
<input type="text" name="phone" size="20" /> <label>Phone Number</label><br />
<input type="text" name="email" size="20" /> <label>Email Address</label><br />
<br />
<textarea name="mess" rows="10" cols="20">Please use this area to type your message.</textarea>

<input type="submit" value="Send Message" name="submit" />

</form>';

}
?>[/code]

Ray
Link to comment
Share on other sites

Hi Ray, 

The id is from the content management system I'm using.  It identifies the page to load.  This page is page 6 in the database and loads it into a template.

When i use your example it takes me to the root index page.  Is there a way to append ?id=6 to what you have?  Would that work?
Link to comment
Share on other sites

no idea why. This is th exact code I am using and it works fine for me.
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Hello!</title>
</head>

<body>
<?php
if (isset($_POST['submit'])) {

extract($_POST);

$subject = "Contact from Firefly website";
$headers = "From: $firstName $lastName <$email>";

$to = $to . "@fireflylightinginnovations.com";

$message = "Email from:" . "\r\n";
$message .= "$firstName $lastName" . "\r\n";
$message .= "$title" . "\r\n";
$message .= "$company" . "\r\n";
$message .= "$phone" . "\r\n";
$message .= "$email" . "\r\n" . "\r\n";
$message .= "Message:" . "\r\n";
$message .= "$mess";

/* mail($to, $subject, $message, $headers); */
echo "$to<br />$headers<br /><br />$message";

echo '<h3>Thank you!</h3> <p>Your message has been sent.  Someone will contact you within 2 business days.</p>';

} else {

echo "<form action=\"".$_SERVER['PHP_SELF']."?id=6\" method=\"post\">";
echo '
<label>Send message to:</label> <select name="to">
<option value="">Select a Recipient</option>
<option value="sales">Sales</option>
<option value="engineering">Engineering</option>
<option value="marketing">Marketing</option>
<option value="service">Customer Service</option>
</select><br />
<br />
<input type="text" name="firstName" size="20" /> <label>First Name</label><br />
<input type="text" name="lastName" size="20" /> <label>Last Name</label><br />
<br />
<input type="text" name="title" size="20" /> <label>Title</label><br />
<input type="text" name="company" size="20" /> <label>Company Name</label><br />
<input type="text" name="phone" size="20" /> <label>Phone Number</label><br />
<input type="text" name="email" size="20" /> <label>Email Address</label><br />
<br />
<textarea name="mess" rows="10" cols="20">Please use this area to type your message.</textarea>

<input type="submit" value="Send Message" name="submit" />

</form>';

}
?>
</body>

</html>[/code]

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.