Jump to content

Required Fields Help!!


jesse24

Recommended Posts

Hello

I have created a contact form and i am having trouble getting the required fields to work. I need Name, number and message as a required field. At the moment all fields have to be completed to be able to submit.

 

Can someone please have a look and let me know what I am doing wrong.

 

Thanks

Jess

 

 

<?php

if ($_POST["email"]<>'') {

 

$ToEmail = '[email protected]';

$EmailSubject = 'Booking Form ';

 

$mailheader = "From: " . $_POST["email"] . "\r\n";

$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

 

$MESSAGE_BODY = "Name: " . $_POST["name"] . "<br>";

$MESSAGE_BODY .= "Address: " . $_POST["address"] . "<br>";

$MESSAGE_BODY .= "Phone: " . $_POST["phone"] . "<br>";

$MESSAGE_BODY .= "Email: " . $_POST["email"] . "<br>";

$MESSAGE_BODY .= "Preferred Bouncer: " . $_POST["bouncer"] . "<br>";

$MESSAGE_BODY .= "Required Date/s: " . $_POST["date"] . "<br>";

$MESSAGE_BODY .= "Required Time/s: " . $_POST["time"] . "<br>";

$MESSAGE_BODY .= "Delivery Location: " . $_POST["location"] . "<br>";

$MESSAGE_BODY .= "Generator: " . $_POST["generator"] . "<br>";

$MESSAGE_BODY .= "Supervisor: " . $_POST["supervisor"] . "<br>";

$MESSAGE_BODY .= "Where did you hear about us: " . $_POST["referral"] . "<br>";

$MESSAGE_BODY .= "Message: " . $_POST["message"] . "<br>";

 

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

 

?>

<?php

$name = $_POST['name'];

$phone = $_POST['phone'];

$message = $_POST['message'];

if (empty($name) || empty($phone) || empty($message))

{

header("Location:http://bouncenbop/contact-bounce-n-bop.php");

exit;

}

?>

 

<div id="formmessage">Your message has been sent successfully.</div>

<?php

} else {

?>

 

        <p align="center">To request one of our fantastic bouncers just complete the enquiry form below and one of team will

                contact you to confirm your booking.</p>

 

<p align="center">For corporate and fundraising packages please contact us directly.</p>

 

                <form action="contact-bounce-n-bop.php" method="post">

                    <fieldset>

                        <legend><strong>Enquiry Form</strong></legend> 

<p class="name"><label for="name">Name: <span class="redstar">*</span></label>

                        <input type="text" name="name"/></p>

<p class="address"><label for="address">Address:</label>

  <input type="text" name="address"/>

</p>

  <p class="phone"><label for="phone">Phone: <span class="redstar">*</span></label>

                        <input type="text" name="phone"/></p>

                        <p class="email"><label for="email">Email:</label>

                        <input type="text" name="email"/></p>

                        <p class="bouncer" align="center"><label for="bouncer">Preferred Bouncer:</label>

                          <select name = "bouncer">

                            <option value = "" selected>Select Bouncer</option>

                            <option value = "Fairy Bouncer w/slide">Fairy Bouncer w/slide</option>

                            <option value = "Incredibles Bouncer w/slide">Incredibles Bouncer w/slide</option>

                            <option value = "Space Ranger w/slide">Space Ranger w/slide</option>

                            <option value = "Robot ">Robot </option>

                            <option value = "Teddy’s Garden">Teddy’s Garden</option>

                            <option value = "Soccer Ball">Soccer Ball</option>

                            <option value = "Spiderman Bouncer">Spiderman Bouncer</option>

                            <option value = "Toy Story Bouncer">Toy Story Bouncer</option>

                            <option value = "Fairies Bouncer">Fairies Bouncer</option>

                            <option value = "Princess Bouncer">Princess Bouncer</option>

                            <option value = "Princess Castle">Princess Castle</option>

                            <option value = "Medieval Castle">Medieval Castle</option>

                            <option value = "Balloon Bouncer">Balloon Bouncer</option>

                            <option value = "Wrecking Ball Game Jnr">Wrecking Ball Game Junior</option>

                            <option value = "Wrecking Ball Game Snr">Wrecking Ball Game Senior</option>

                          </select>

                        </p>

                  <p class="dates"><label for="date">Date/s Required:</label>

                        <input type="text" name="date"/></p>

                        <p class="time"><label for="time">Time/s Required:</label>

                        <input type="text" name="time"/></p>

                        <p class="location"><label for="location">Delivery Location:</label>

                        <input type="text" name="location"/></p>

                      <p align="center"><label for="requirements">Other Requirements:</label><br/>

                          <input type="checkbox" name="generator"/> Generator<br/>

                        <input type="checkbox" name="supervisor"/> Supervisor</p>

                        <p align="center"><label for="referral">How did you hear about us?:</label>

<select name = "referral">

                                <option value = "" selected>Please Select</option>

                                <option value = "Referred by a friend">Referred by a friend</option>

                                <option value = "Internet">Internet </option>

                                <option value = "Flyer">Flyer</option>

                                <option value = "School">School </option> 

                                <option value = "Daycare Centre">Daycare Centre</option>

                                <option value = "Used one of my 3 wishes">Used one of my 3 wishes</option>

                                <option value = "Other">Other  </option>   

                      </select></p>

                        <p align="center"><label for="message">Message: <span class="redstar">*</span></label><br/>

                        <textarea name="message"></textarea></p>

                        <p align="center"><input type="submit" name="submit" value="Submit"/></p>

                        </fieldset>

                        </form>

                       

                <p class="mobile"><strong>Mobile:</strong><br/>

            0433 893 186 </p>

            <p class="addy"><strong>Postal Address:</strong><br/>

            PO Box 256 Quinns Rocks 6030<br/>

            </p>

            <p class="eaddy"><strong>Email Address:</strong><br/>

            <a href="mailto:[email protected]">[email protected]</a></p>

<?php

}

?>

               

                </div><!--endcontact-->

 

<!-- InstanceEndEditable -->

            </div><!--endcontent-->

 

        <div id="footer-one">

            <img src="images/layout/starlight-supporter.jpg" />

                <p>Member of the Australian Amusement, Leisure and Recreation Association Inc</p>

        </div><!--endfooter-one-->

           

            <div id="footer-two">

            <p><strong>M - 0433 893 186<br/>

                <a href="mailto:[email protected]">E – [email protected]</a></strong></p>

            </div><!--endfooter-two-->

      </div><!--endcontainer-->

<div style="clear:both;"></div>

      <div id="out-footer">

      Bounce 'N' Bop © 2009 - All Rights Reserved | Website by <a href="http://www.jesseswebdesigns.com.au">Jesse's Web

        Designs </a>2009<br/>

        This website displays better in <a href="http://www.microsoft.com/windows/internet-explorer/thank-you.aspx">IE8</a></p>

      </div>

   

</body>

<!-- InstanceEnd --></html>

 

Link to comment
https://forums.phpfreaks.com/topic/185687-required-fields-help/
Share on other sites

There is a lot of code to read through, but I can't find much wrong if I am reading it correctly. I haven't spent time over it but.

 

Please insert your code pastes inside <code> blocks like: <code> some code </code> but instead of pointy brackets use the square ones.

 

One thing I saw is you are using empty() to check if the required fields are filled out. Check out http://au2.php.net/manual/en/function.empty.php as a value can be "empty" even if it's not really empty. In your case, I would prefer to use strlen() to check if the required fields have desired data in them.

 

 

Upon more inspection, I think your logical flow in that code is doing this:

 

if email address is set
{
set some variables
mail() the message
if required fields are not set
{
  output error page
}
}
else
{
  output page for booking a bouncer
}

 

maybe you should be checking if the required fields are set before you are actually mail() ing the message?

Link to comment
https://forums.phpfreaks.com/topic/185687-required-fields-help/#findComment-980487
Share on other sites

Thankyou for your reply!

I am not very good with PHP and have trouble trying to understand it, as you can probably tell.

Is the below code what you meant? I don't know how strlen() should work or look.

 

Thanks again.

 

 

<code>

<?php

if ($_POST["email"]<>'') {

 

$ToEmail = '[email protected]';

$EmailSubject = 'Booking Form ';

 

$mailheader = "From: " . $_POST["email"] . "\r\n";

$mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

 

$name = $_POST['name'];

$phone = $_POST['phone'];

$message = $_POST['message'];

if (strlen($name) || strlen($phone) || strlen($message))

{

header("Location:http://bouncenbop/contact-bounce-n-bop.php");

exit;

}

 

$MESSAGE_BODY = "Name: " . $_POST["name"] . "<br>";

$MESSAGE_BODY .= "Address: " . $_POST["address"] . "<br>";

$MESSAGE_BODY .= "Phone: " . $_POST["phone"] . "<br>";

$MESSAGE_BODY .= "Email: " . $_POST["email"] . "<br>";

$MESSAGE_BODY .= "Preferred Bouncer: " . $_POST["bouncer"] . "<br>";

$MESSAGE_BODY .= "Required Date/s: " . $_POST["date"] . "<br>";

$MESSAGE_BODY .= "Required Time/s: " . $_POST["time"] . "<br>";

$MESSAGE_BODY .= "Delivery Location: " . $_POST["location"] . "<br>";

$MESSAGE_BODY .= "Generator: " . $_POST["generator"] . "<br>";

$MESSAGE_BODY .= "Supervisor: " . $_POST["supervisor"] . "<br>";

$MESSAGE_BODY .= "Where did you hear about us: " . $_POST["referral"] . "<br>";

$MESSAGE_BODY .= "Message: " . $_POST["message"] . "<br>";

 

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

 

?>

 

 

<div id="formmessage">Your message has been sent successfully.</div>

<?php

} else {

?>

</code>

Link to comment
https://forums.phpfreaks.com/topic/185687-required-fields-help/#findComment-980489
Share on other sites

Not sure 100% if that would work, as strlen returns an integer and 0 if there is nothing, so I don't know if the 0 would return as "false" or not. Check out strlen reference page: http://au2.php.net/manual/en/function.strlen.php

 

You can change it to:

if (strlen($name) == 0 || ...)

to make sure it will work.

 

What output does the page give you at the moment? And what output do you expect? Apart from it throwing warnings about unassigned variable names if you don't pass all the form values, I don't see why it would not send the message unless the email is not entered.

 

Link to comment
https://forums.phpfreaks.com/topic/185687-required-fields-help/#findComment-980490
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.