Jump to content

Recommended Posts

Good afternoon,

 

I've created two pages to handle a request form that handles the following information: length width height name email and address.  Once the form is filled out and submitted, it goes to a second page where it tells you if a) the dimensions will or will not fit b)if you didn't fill in your name, email or phone, you get a reminder to do so and c)sends an email of all info put into the form.

 

My two questions are this:

1. Can I just have 1 php page handle this instead of two?

2.  How do write something so that if the contact information fields from the form aren't filled out, an email isn't generated, instead you're promted to fill out the req'd forms before continuing?

 

My code is below.  THANK YOU so much for taking the time to peruse this.

 

The intial page with the form:

<form action="accumen_request_handle.php" method="post">

 

<b>Describe the largest object which needs to be moved (in inches).</b> <br /><br />

 

Height? <input type = "text" name="height" type="text" size="2" maxlength="6" /> inches<p>

 

Length? <input type ="text" name="length" type="text" size="2" maxlength="6" /> inches<p>

 

Width? <input type ="text" name="width" type="text" size="2" maxlength="6" /> inches<p>

<br />

Client Name: <input type ="text" name="client_name" type="text" size="25" /><p></p>

Phone Number: <input type ="text" name="client_phone" type="text" size="25" maxlength="10" /><p></p>

E-mail Address: <input type ="text" name="client_email" type="text" size="25" /><p></p>

 

<input type="submit" name="submit" value="Submit Your Request" />

</form>

 

The page that handles the form

<?php //set variables from form

$height = $_POST["height"];

$width = $_POST ["width"];

$length = $_POST["length"];

$name = $_POST["client_name"];

$number = $_POST["client_phone"];

$email = $_POST["client_email"];

$strip_height = strip_tags($_POST['height']);

$strip_width = strip_tags($_POST['width']);

$strip_length = strip_tags($_POST['length']);

$strip_client_name = strip_tags($_POST['client_name']);

$strip_client_phone = strip_tags($_POST['client_phone']);

$strip_client_email = strip_tags($_POST['client_email']);

$total_height = 90;

$total_width = 91;

$total_length = 192;

 

 

if (($strip_height <= $total_height) and ($height) > 0 ){  //if height is less than total height

print("This will fit height-wise.");

}

elseif($strip_height >= $total_height) { //if height is more than total height

print("Sorry, but this won't fit because it's too tall.");

}

 

if (($strip_width <= $total_width) and ($width) > 0) {  //if width is less than total width

print ("This will fit width-wise.");

}

elseif($strip_width >= $total_width) { //if width is more than total width

print("Sorry, but this won't fit because it's too wide.");

}

 

if (($strip_length <= $total_length) and ($length) > 0) {  //if length is less than total length

print("This will fit length wise.");

}

elseif($strip_length >= $total_length) { //if length is more than total length

print("Sorry, but this won't fit because it's too long.");

}

 

//height?

if (empty($_POST['height'])) {

print '<p class="error">Please enter a height.</p>';

$okay = FALSE;

}

//width

if (empty($_POST['width'])) {

print '<p class="error">Please enter a width.</p>';

$okay = FALSE;

}

//length?

if (empty($_POST['length'])) {

print '<p class="error">Please enter a length.</p>';

$okay = FALSE;

}

//client name?

if (empty($_POST['client_name'])) {

print '<p class="error">Please enter your name.</p>';

$okay = FALSE;

}

//phone number?

if (empty($_POST['client_phone'])) {

print '<p class="error">Please enter your phone number.</p>';

$okay = FALSE;

}

//email address?

if (empty($_POST['client_email'])) {

print '<p class="error">Please enter your email address.</p>';

$okay = FALSE;

}

 

?>

 

 

<?php 

 

$to = "[email protected]";

$subject = "Web Order Received";

//$body = "An order from the web site has been submitted.\n";

$content ="Height is $strip_height inches.\n Length is $strip_length inches.\n Width is $strip_width inches.\n  Client Name is $strip_client_name.\n Client Email is $strip_client_email.\n Client phone number is $strip_client_phone";

if (mail($to, $subject,$content)) {

  print("<p>Your order has been successfully sent! We'll be contacting you shortly.</p>");

  } else {

  print("<p>Your order has not been successfully sent!</p>");

  }

?>

 

<br /> <br />

<?php //print current date and time:

//set the time zone:

date_default_timezone_set('America/New_York');

 

//now print the date and time:

print date('g:i a l F j');

print " EST"

?>

 

My 2cents...

 

(fyi - there is a button

 - it will create 2 tags, place your code between the tags)

 

Now to your question(s).

 

1. Yes, you can do it all on one page. My personal pref = 2 pages

 

2. Whether you use 1 page or two, start the pages wirth session_start. that way you can pass easily pass information (error messages, good data) back to the form.

 

3. Try to keep your error messages in an array before outputting them. It makes it easier (for me anyway)

 

4. Do all your error checking (when possible) near the top of your script - no need to do calculations or confrimation messages when later in the page errors may be found.

 

its a start.

Make sense?

 

Thanks for the tips.  I agree that two pages seems to be the way to go.  It seems like there should be a way to stop the form from processing if it's missing key data (the name,email, and phone, for instance) but I've yet to find a way to do that.  Some other pieces of code I've tried haven't worked because as soon as you go to the page it sees that those required fields are empty and you get an error message.  Would using session_start solve this problem?

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.