Page 1 of 1

form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 5:18 am
by Architek
Hello,

I am new to PHP but am here sitting in front of my machine at 3am going through various threads and looking at ways others have developed code. I have a little project and am not sure what is going on and have honestly tried to understand the logic before asking stupid questions.

Here it goes.

I have a simple HTML form that I am passing variables to a php script through the post method. The values are received just fine on the first pass. I have a couple If statements check to see if the name and email fields have some sort of value before proceeding.

Lets say I fill out the form in its entirety and submit it pursues and I get the expected email process to function. If I fail to fill in a value for one of the required fields it creates an out put page of say... "Check name field" so I use the back button and fill in the value then click submit and it thinks the value is not present. I have even had the IF statement push me to a new header page on my site and then navigate back to the form and still the same result.

Is this an issue with my form or the php script? I am not creating any specific cookie or defining a session instance.

Here is my code... any thing you can suggest or slap me silly with is appreciated. :banghead:

HTML Form....

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>somewhere.com</title>
    <link href="bg.css" rel="stylesheet" type="text/css" media="screen" />
</head>
    <body>
        <div id="container">
            <div id="header">
                <div id="nav">
                    <a href="index.html" class="navbutton">Home</a><a href="portfolio.html" class="navbutton">Portfolio</a><a href="contact.html" class="navbutton">Contact</a>
                </div>
            </div>
            <div id="message">
                <h1>Contact Information</h1>
                <div id="mesnav">
                    <p><a href="contact.html" class="contactopts">Someone</a></p>
                    <p><a href="contact_local.html" class="contactopts">Local Shop</a></p>
                    <p class="selected">Appointment Request</p>
                    <p><a href="contact_sendexample.html" class="contactopts">Send Example</a></p>
                </div>
            </div>
                <div id="minipg">
                    <form method="post" action="email.php" name="apptreq" id="apptreq"  enctype="text/plain">
                        <h2>Appointment Request Form</h2>
                        <table>
                            <tr>
                                <td>Your Name:</td>
                            </tr>
                            <tr>
                                <td><input type="text" name="name" id="name" /></td>
                            </tr>
                            <tr>
                                <td>Email Address:</td>
                            </tr>
                            <tr>
                                <td><input type="text" name="from" id="from" /></td>
                            </tr>
                        </table>
                        <table>
                            <tr>
                                <td>Body Object:</td><td>Canvas Type:</td>
                            </tr>
                            <tr>
                                <td><input type="text" name="bodypart" id="bodypart" /></td><td><select name="skin" id="skin">
                                                                                                    <option value="Select..." selected="selected">Please Select...</option>
                                                                                                    <option value="Is it Gonna Hurt???">Is it Gonna Hurt???</option>
                                                                                                    <option value="Wanna see my cute Tan?">Wanna see my cute Tan?</option>
                                                                                                    <option value="I have Fair Skin">I have Fair Skin</option>
                                                                                                    <option value="I am a tough SOB!">I am a tough SOB!</option>
                                                                                                    <option value="Darker than you!">Darker than you!</option>
                                                                                                    <option value="Who cares!">Who cares!</option>
                                                                                                    </select></td>
                            </tr>
                            <tr>
                                <td>Size:</td>
                            </tr>
                            <tr>
                                <td><input type="text" name="size" id="size" /></td><td><input type="radio" name="color" value="black & White" id="black" /><label for="black">Black & White</label><input type="radio" name="color" value="Mixed Color" id="color" /><label for="color">Mixed Color</label></td>
                            </tr>
                        </table>
                        <table>
                            <tr>
                                <td>Description:</td>
                            </tr>
                            <tr>
                                <td><textarea cols="45" rows="4" name="description" id="description"></textarea></td>
                            </tr>
                            <tr>
                                <td><input type="submit" name="submit" id="submit" value="Submit Request" class="button" /><input type="reset" value="Reset Form" class="button" /></td>
                            </tr>
                        </table>
                        <p>** Deposit may be required to hold appointment.</p>
                    </form>
                </div>
        <div id="footer">
            <p><b>Copyright &#169; - somewhere.com</b> - <em>Site coded by somewhere.com</em></p>
        </div>
        </div>
    </body>
</html>
 

Code: Select all

 
PHP script....
 
<?php
//if(isset($_POST["name"])) $name=$_POST["name"];
//if(isset($_POST["from"])) $from=$_POST["from"];
 
$name=$_POST["name"];
$from=$_POST["from"];
$error="";
 
if($name == "") $error="<br /><br />"."*Please enter your name";
if($from == "") $error="<br />"."*Please enter your email"."<br /><br />";
 
if($error == ""){
 
 
//if($from == "") {echo "Looks like we need your email address please..." ;}
//else {
//if($name == "") {echo "Looks like we need your name please..." ;}
//else {
 
$headers = "From: $from";
$subject = "somewhere.com - New Appointment Request";
$to = "someone@somewhere.com";
 
$fields = array();
$fields{"name"} = "name";
$fields{"from"} = "from";
$fields{"bodypart"} = "bodypart";
$fields{"skin"} = "skin";
$fields{"size"} = "size";
$fields{"color"} = "color";
$fields{"description"} = "description";
 
$body = "You have a new appointment request from with the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_POST[$a]); }
 
$headers2 = "From: noreply@somewhere.com";
$subject2 = "somewhere.com - New Appointment Request";
$autoreply = "Thank you for your request.\n\nI should be able to review the information provided and get back to you shortly. In the event I do not respond within 48 hours please feel free to contact me directly. You can find my information in the same area you submited this request at http://www.somewhere.com\n\nIn the event you have received this message in error please contact the administrator at webmaster@somewhere.com\n\nThank you!\nSomeones Name";
 
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.somewhere.com/thankyou.html" );}
else
 
{echo "We encountered an error sending your mail, please notify webmaster@somewhere.com";}
}
Else{Echo "Sorry it appears you didn't fill in the following field(s)" .$error. "Please go back and verify before proceeding.";
}
?>
 

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 11:19 am
by Architek
bump...

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 12:07 pm
by Reviresco
Please explain exactly what the problem is more clearly. What is it doing or not doing?

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 12:19 pm
by Architek
here is the current link...
http://www.centerpointtattoo.com/contac ... tment.html

first enter all the information on the form or at least the first two fields... If you do so it works fine.


If I then re-navigate back to the page and proceed to fill out the form and fail to fill in one of the two fields either Name or Email it sends you to an error page. If I click back to fill in the field with my name or email and submit so the form is now complete it still thinks the value is missing.

hope that helps.

I have tried different iterations of if logic and it seems to be the same result.

Thanks!

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 12:38 pm
by Reviresco
Architek wrote:here is the current link...
http://www.centerpointtattoo.com/contac ... tment.html

first enter all the information on the form or at least the first two fields... If you do so it works fine.
When I enter name and email address and hit submit, I go to email2.php with the message "Looks like we need your email address please..."

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 1:28 pm
by Architek
well I created 3 different versions now (contact_appointment, contact_appointment2, contact_appointment3)... and every one doesn't seem to work. I don't even see my POST values coming through any more... its driving me nuts... I don't know if its my code or an actual server issue with who I am hosted through.

I am going to move everything to my own personal server and see whats up...

I guess does it look like there are any issues with my initial code below?

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 2:46 pm
by Architek
well... all my troubles seem to be contributed to the form method. when I use GET or REQUEST in both the form and the php script everything works fine. as soon as I change the from method to POST it fails.

any ideas?

Re: form issue not sure how to reset variables passed to script

Posted: Wed Jul 01, 2009 2:48 pm
by Architek
just noticed this is posted in the wrong section of the forum. oops.

Re: form issue not sure how to reset variables passed to script

Posted: Fri Jul 03, 2009 9:07 am
by SeaJones
i'm sure a mod will move it at some point.