Jump to content

Recommended Posts

ok I have a PHP form that I want to make Name Email and Phone required using javascript how would I do this here is my .php and html form.

 

<?PHP 
$to = "";  
$subject = "Results from your Request Info form";
$headers = "From: Tampabaychartering.net";
$forward = 0;
$location = "";

$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 


$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) { 
	$msg .= ucfirst ($key) ." : ". $value . "\n"; 
}
}
else {
foreach ($_GET as $key => $value) { 
	$msg .= ucfirst ($key) ." : ". $value . "\n"; 
}
}

mail($to, $subject, $msg, $headers); 
if ($forward == 1) { 
    header ("Location:$location"); 


} 
else { 
header("Location: http://www.tampabaychartering.com/booking.html");
exit ();

}

?>

<hr>
<form action="booking.php" method="post" name="ContactForm" onsubmit="return ValidateContactForm();">


  <p align="left">
  <b><font face="Comic Sans MS" size="4" color="#003366">Type of Charter 
  <select size="1" name="type_of_charter">
  <option selected>Flats Fishing</option>

  <option>Inshore Fishing</option>
  <option>Offshore Fishing</option>
  </select></font></b></p>
      
  <p align="left">
  <b><font face="Comic Sans MS" size="4" color="#003366">Have you fished with me 
  before?
  <select size="1" name="have_fished_with_you_before">
    <option>yes</option>

    <option selected>no</option>
  </select></font></b></p>

<p align="left"><font face="Comic Sans MS" size="4" color="#003366"><b>How
  many days do you want to fish? </b></font><b>
  <font face="Comic Sans MS" size="4" color="#003366">
  <select size="1" name="days_you_want_to_fish">
    <option selected>1</option>
    <option>2</option>
    <option>3</option>

    <option>4</option>
    <option>5</option>
  </select> </font></b></p>
  <p align="left"><b><font color="#003366" size="4" face="Comic Sans MS">How 
  Long of a trip do you want
  <select size="1" name="how_long_do_you_want_to_fish">
  <option selected>Full Day Flats  $450</option>
  <option>Full Day Inshore  $450</option>
  <option>Full Day Offshore  $650</option>


  </select></font></b></p>

  <p align="left"><b><font face="Comic Sans MS" size="4" color="#003366">How 
  many people in your party? For parties of more than 4 please call before booking.<select size="1" name="how_many_people">
  <option>1</option>
  <option selected>2</option>
  <option>3</option>
  <option>4</option>
  </select></font></b></p>

  
  <p align="left" style="margin-top:">
  <b><font face="Comic Sans MS" size="4" color="#003366">How many adults? 
  <select size="1" name="adults_in_group">
  <option selected>1</option>

  <option>2</option>
  <option>3</option>
  <option>4</option>


  </select> How Many children under 12? <select size="1" name="number_of_children">
  <option>0</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  
  </select></font></b></p>
  <p align="left"><b><font color="#003366" size="4" face="Comic Sans MS">Choose
  the date Of your Charter.</font></b></p>
  <p align="left"><b><font color="#003366" face="Comic Sans MS" size="4">
  <select size="1" name="Charter_Date">
    <option selected>January</option>
    <option>February</option>

    <option>March</option>
    <option>April</option>
    <option>May</option>
    <option>June</option>
    <option>July</option>
    <option>August</option>

    <option>September</option>
    <option>October</option>
    <option>November</option>
    <option>December</option>
  </select>  
  <select size="1" name="day">
    <option selected>1</option>

    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>

    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>

    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>

    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>

    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>


  </select>  <select size="1" name="year">
    <option selected="">2011</option>

  	<option>2012</option>
<option>2013</option>
<option>2014</option>
  </select></font></b></p>

<p align="left"><b><font face="Comic Sans MS" size="4" color="#003366">Payment method preffered for deposit?<select size="1" name="Deposit_Payment_Method">
  <option>Credit Card</option>
  <option selected>Money Order</option>
  </select></font></b></p>
  
<p><strong><font color="#003366" size="4" face="Comic Sans MS">How can I get in touch with you?</font></strong></p>
  
  <dl>

    <dd>
      <table height="150">
        <tr>
          <td height="27">
            <p align="left"><b>
            <font size="4" face="Comic Sans MS" color="#003366">Name </font></b>
          <td height="27">
            <p align="left">

            <font face="Comic Sans MS" size="4"><b><font color="#003366">
            <input type="text" size="35" maxlength="256" name="name">
            </font></b><font color="#FF0000">required</font><b><font color="#003366">
            </font></b></font>
        </tr>
        <tr>
          <td height="27">
            <p align="left"><b>

            <font size="4" face="Comic Sans MS" color="#003366">E-mail </font>
            </b>
          <td height="27">
            <p align="left"><font face="Comic Sans MS" size="4"><b>
            <font color="#003366">
            <input type="text" size="35" maxlength="256" name="email">
            </font></b></font>
        </tr>

        <tr>
          <td height="27">
            <p align="left"><b>
            <font size="4" face="Comic Sans MS" color="#003366">Home </font></b>
          <td height="27">
            <p align="left">
            <font face="Comic Sans MS" size="4"><b><font color="#003366">
            <input type="text" size="35" maxlength="256" name="phone">

            </font></b><font color="#FF0000">required 10 digits </font><font color="#003366">
             </font></font></tr>
        <tr>
          <td height="27">
            <b><font size="4" face="Comic Sans MS" color="#003366">Work</font></b><td height="27">
            <font size="4" face="Comic Sans MS" color="#003366"><b>
            <input type="text" size="35" maxlength="256" name="Work_number"></b></font></tr>
        <tr>
          <td height="27">
            <p align="left"><b>
            <font size="4" face="Comic Sans MS" color="#003366">Cell</font></b><td height="27">
            <p align="left">
            <font face="Comic Sans MS" size="4"><b><font color="#003366">
            <input type="text" size="35" maxlength="256" name="User_cell ">
            </font></b></font>
        </tr>

      </table>
    </dd>
  </dl>
  <p align="left"><font face="Comic Sans MS"><b><font size="4" color="#003366">What is the best time to call?   
  </font></b>
      <font color="#003366"><b><font size="4">From</font></b></font></font><font face="Comic Sans MS" size="4"><b><font color="#003366"><select size="1" name="best_time_to_call">
        <option selected>8am</option>

        <option>9am</option>
        <option>10am</option>
        <option>11am</option>
        <option>12am</option>
        <option>1pm</option>
        <option>2pm</option>

        <option>3pm</option>
        <option>4pm</option>
        <option>5pm</option>
        <option>6pm</option>
        <option>7pm</option>
        <option>8pm</option>

        <option>9pm</option>
        <option>10pm</option>
      </select> </font></b></font><font face="Comic Sans MS"> <b>
  <font size="4" color="#003366">To </font></b></font>
  <font face="Comic Sans MS" size="4"><b><font color="#003366"><select size="1" name="until">
        <option>8am</option>

        <option>9am</option>
        <option>10am</option>
        <option>11am</option>
        <option>12am</option>
        <option>1pm</option>
        <option>2pm</option>

        <option>3pm</option>
        <option>4pm</option>
        <option>5pm</option>
        <option>6pm</option>
        <option>7pm</option>
        <option>8pm</option>

        <option>9pm</option>
        <option selected>10pm</option>
      </select>  </font></b></font>
  <p align="left"><b><font face="Comic Sans MS" size="4" color="#003366">How 
  would you prefer to be contacted?
  <select size="1" name="Prefer_to_be_contacted_by">
  <option selected>Home Phone</option>
  <option>Work Phone</option>

  <option>Cell Phone</option>
  <option>E-mail</option>
  </select></font></b><p align="left"><b>
  <font color="#003366" face="Comic Sans MS" size="4">What time zone are you in <select size="1" name="Time_zone">
        <option selected>Eastern</option>
        <option>Central</option>

        <option>Mountain</option>
        <option>Pacific</option>
        <option>Out of USA</option>
      </select></font></b><p align="left"><font color="#FF0000" size="4"><b>Questions or comments about your trip</b></font></p>
  <p align="left"><textarea rows="5" name="Comments" cols="67"></textarea></p>
  <p align="left"> </p>

  <p align="left">
  <b>
  <font color="#003366" size="4" face="Comic Sans MS">We will contact you as soon as possible to finish Booking your fishing trip.</font></b></p>
  <p>
  <input type="submit" value="Submit"> 
  <input type="reset" value="Clear Form"></p>
</form>

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

I would strongly advise against validating the form using JS - unless of course you replicate the validation within the PHP too. The reason for this is that JavaScript is a client-side scripting language, where the user can easily disable or even modify the code to bypass the validation. You can't trust it, basically.

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.