croakingtoad Posted December 12, 2006 Share Posted December 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/ Share on other sites More sharing options...
.josh Posted December 12, 2006 Share Posted December 12, 2006 use $_POST['email'] Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139817 Share on other sites More sharing options...
The Little Guy Posted December 12, 2006 Share Posted December 12, 2006 if (isset($_POST['email']) && isset($_POST['submit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139818 Share on other sites More sharing options...
wildteen88 Posted December 12, 2006 Share Posted December 12, 2006 Use $_POST['email] not $emailYou will need to do this for all variables you use for access the fields from the form, eg:$_POST['to'], $_POST['firstName'], $_POST['lastName'] etc Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139820 Share on other sites More sharing options...
The Little Guy Posted December 12, 2006 Share Posted December 12, 2006 your message variables won't work unless you change them, ans same with your headers. Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139821 Share on other sites More sharing options...
croakingtoad Posted December 12, 2006 Author Share Posted December 12, 2006 Thanks!!Just out of curiosity is there a way to have the variables converted from $_POST['email] to just $email with one generic line or two of code? Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139824 Share on other sites More sharing options...
spfoonnewb Posted December 12, 2006 Share Posted December 12, 2006 Put[code]$email = $_POST['email'];[/code]Above that code. (Like right under the <?php) Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139825 Share on other sites More sharing options...
croakingtoad Posted December 12, 2006 Author Share Posted December 12, 2006 [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..? Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139828 Share on other sites More sharing options...
spfoonnewb Posted December 12, 2006 Share Posted December 12, 2006 Don't think so. Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139830 Share on other sites More sharing options...
.josh Posted December 12, 2006 Share Posted December 12, 2006 extract($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139831 Share on other sites More sharing options...
croakingtoad Posted December 12, 2006 Author Share Posted December 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139862 Share on other sites More sharing options...
craygo Posted December 12, 2006 Share Posted December 12, 2006 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 variableI 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]<?phpif (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 Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139866 Share on other sites More sharing options...
croakingtoad Posted December 12, 2006 Author Share Posted December 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139889 Share on other sites More sharing options...
craygo Posted December 12, 2006 Share Posted December 12, 2006 yes you can still add the id part in. I jumped the gun on fixing that.[code]echo "<form action=\"".$_SERVER['PHP_SELF']."?id=6\" method=\"post\">";[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139900 Share on other sites More sharing options...
croakingtoad Posted December 12, 2006 Author Share Posted December 12, 2006 okay...so when I add the id back in (copy your line above) it just reloads the page again...back to the same problem...ARGH! Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139916 Share on other sites More sharing options...
craygo Posted December 12, 2006 Share Posted December 12, 2006 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><?phpif (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 Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-139920 Share on other sites More sharing options...
.josh Posted December 13, 2006 Share Posted December 13, 2006 is the codeblock you are providing possibly inside some other condition that isn't being met? Like..something having to do with this whole id business, or something? Quote Link to comment https://forums.phpfreaks.com/topic/30383-form-doesnt-submit-to-self/#findComment-140222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.