I'm writing a registration page in with PHP:
<form action="" method="post">
<input type="text" id="lname" name="fname" placeholder="First Name" required>
<input style='margin:8px;'type="text" id="fname" name="lname" placeholder="Last Name" required>
<br>
<br>
<input type="emailtext" id="email" name="email" placeholder="Email Address" required>
<br>
<div class="selectdiv" required>
<p class="boldlabel">I am a</p>
<input type="radio" id="tutor" name="tutororstudent" value="tutor" required>
<label for="tutor">Tutor</label><br>
<input type="radio" id="student" name="tutororstudent" value="student">
<label for="student">Student</label><br>
<div class="innerdiv">
<p class="boldlabel">Grade level</p>
<select name="grade">
<option value="1">1st Grade</option>
<option value="2">2nd Grade</option>
<option value="3">3rd Grade</option>
<option value="4">4th grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th grade</option>
<option value="13">Undergrad/grad</option>
<option value="14">Post College</option>
</select>
</div>
</div>
<input style='margin:16px;'type="password" id="pwd" name="pwd" placeholder="Password" required>
<input type="submit" value="Register">
</form>
I want the div "innerdiv" to only show up if the user selects the student radio button. How do I do this in PHP? How do I hide it until the user selects the student radio button?
You only can achieve that using javascript:
add id to your innerdiv.
<div class="innerdiv" id="innerdiv" style="display:none">
<p class="boldlabel">Grade level</p>
<select name="grade">
<option value="1">1st Grade</option>
<option value="2">2nd Grade</option>
<option value="3">3rd Grade</option>
<option value="4">4th grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th grade</option>
<option value="13">Undergrad/grad</option>
<option value="14">Post College</option>
</select>
</div>
bottom of your page, put this:
<script>
let student = document.getElementById('student');
student.addEventListener('click', display);
let tutor = document.getElementById('tutor');
tutor.addEventListener('click', () => div.style.display = "none");
let div = document.getElementById('innerdiv');
function display(){
if(student.checked) {
div.style.display = "block";
}
}
</script>
Related
I am setting up a web page that outputs the form data that has been input from a different page, and I'm having trouble getting that data to process and submit. I want the second web page to have the output outlined in the HTML code below. The first section of HTML is the first page known as reservations.html and I want to submit to the contactform.php page.
<form class="reservation-form" action="contactform.php" method="post" ng-submit="processForm()">
<fieldset>
<legend>Contact Information</legend>
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" class="form-control" ng-model="formData.firstname" ><br><br>
<label for="middlename">Middle Name:</label>
<input type="text" id="middlename" name="middlename" class="form-control" ng-model="formData.middlename"><br><br>
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" class="form-control" ng-model="formData.lastname"><br><br>
<label for="phone"> Phone Number: </label>
<input type="tel" name="phone" class="form-control" ng-model="formData.phone"><br><br>
<label for="email">Email Address: </label>
<input type="email" name="email" class="form-control" ng-model="formData.email"><br><br>
</fieldset>
<fieldset>
<legend>Travel Information</legend>
<label for="locations">Current Locations:</label>
<select name="locations" id="locations" onchange="activites('locations', 'activitiesList')" ng-model="formData.locations">
<option value="australia">Brisbane</option>
<option value="canada">Vancouver</option>
<option value="newyork">New York City</option>
<option value="germany">Berlin</option>
<option value="mexico">Cancun</option>
</select><br><br>
<label for="depart-date">Departure Date: </label>
<input type="date" name="depart-date" id="depart-date" ng-model="formData.departuredate"><br><br>
<label for="return-date">Return Date: </label>
<input type="date" name="return-date" id="return-date" ng-model="formData.returndate"><br><br>
<label for="needed">Options</label><br>
<input type="checkbox" name="needed" value="flight" ng-model="formData.flight"> Flight<br>
<input type="checkbox" name="needed" value="hotel" ng-model="formData.hotel"> Hotel<br>
<input type="checkbox" name="needed" value="car" ng-model="formData.car"> Rental Car<br><br>
</fieldset>
<div id="activities" class="">
<label class="">Choose an Activity</label>
<select id="activitiesList" name="activities" ng-model="formData.activities">
</select>
</div>
<fieldset>
<legend>Billing Information</legend>
<label for="line1">Address Line 1:</label>
<input type="text" id="line1" name="line1" ng-model="formData.line1"><br><br>
<label for="line2">Address Line 2:</label>
<input type="text" id="line2" name="line2" ng-model="formData.line2"><br><br>
<label for="city">City: </label>
<input type="text" name="city" ng-model="formData.city"><br><br>
<label for="state">State: </label>
<select name="state" id="state" ng-model="formData.state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><br><br>
<label for="zip">Zip Code: </label>
<input type="text" name="zip" id="zip" ng-model="formData.zip"><br><br>
</fieldset>
<button ng-click="submit()" style="color:black;font-size:1em;">
<b>Submit</b>
</button><br><br>
<button ng-click="reset()" style="color:black;font-size:1em;">
<b>Reset</b>
</button><br><br>
</form>
<?php
if (isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$locations = $_POST["locations"];
$depart = $_POST["depart-date"];
$return = $_POST["return-date"];
$options = $_POST["options"];
$line1 = $_POST["line1"];
$line2 = $_POST["line2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$departDB = strtotime($depart);
$returnDB = strtotime($return);
$departDB = date('Y-m-d', $departDB);
$returnDB = date('Y-m-d', $returnDB);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Form</title>
</head>
<body>
<h1>Thank You</h1>
<p>Here is the information you have submitted:</p>
<ol>
<li><em>First Name:</em> <?php echo $_POST["firstname"]?></li>
<li><em>Middle Name:</em> <?php echo $_POST["middlename"]?></li>
<li><em>Last Name:</em> <?php echo $_POST["lastname"]?></li>
<li><em>Phone Number:</em> <?php echo $_POST["phone"]?></li>
<li><em>Email:</em> <?php echo $_POST["email"]?></li>
<li><em>Location:</em> <?php echo $_POST["locations"]?></li>
<li><em>Departure Date:</em> <?php echo $_POST["depart-date"]?></li>
<li><em>Return Date:</em> <?php echo $_POST["return-date"]?></li>
<li><em>Options Selected:</em> <?php echo $_POST["options"]?></li>
<li><em>Address Line 1:</em> <?php echo $_POST["line1"]?></li>
<li><em>Address Line 2:</em> <?php echo $_POST["line2"]?></li>
<li><em>City:</em> <?php echo $_POST["city"]?></li>
<li><em>State:</em> <?php echo $_POST["state"]?></li>
<li><em>Zip Code:</em> <?php echo $_POST["zip"]?></li>
</ol>
</body>
</html>
There is no form tag AND Submit button
<form method="POST" action="">
...
<input type="text" name="firstname" value="">
.. And all other fields ..
...
<input type="submit" name="submit" value="send">
</form>
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ShipOnline System</title>
</head>
<body>
<h1>ShipOnline System Request Page</h1>
<form method="post" action="request.php">
<fieldset>
<fieldset>
<legend>Item Information:</legend>
<p><label for="description">Description:</label>
<input type="text" name= "description" id="description" maxlength="100" size="20" required="required"/></p>
<p><label for="weight">Weight (kg):</label>
<select name="weight" id="weight" required="required">
<option value="">Please Select</option>
<option value="weight">0-2</option>
<option value="weight">3</option>
<option value='weight'>4</option>
<option value='weight'>5</option>
<option value='weight'>6</option>
<option value='weight'>7</option>
<option value='weight'>8</option>
<option value='weight'>9</option>
<option value='weight'>10</option>
<option value='weight'>11</option>
<option value='weight'>12</option>
<option value='weight'>13</option>
<option value='weight'>14</option>
<option value='weight'>15</option>
<option value='weight'>16</option>
<option value='weight'>17</option>
<option value='weight'>18</option>
<option value='weight'>19</option>
<option value='weight'>20</option>
</select></p>
</fieldset>
<fieldset>
<legend>Pick-up Information:</legend>
<p><label for="pickupAddress">Street Address:</label>
<input type="text" name= "pickupAddress" id="pickupAddress" maxlength="40" size="30" required="required"/></p>
<p><label for="pickupSuburb">Suburb:</label>
<input type="text" name= "pickupSuburb" id="pickupSuburb" maxlength="40" size="20" required="required"/></p>
<p><label for="date">Preferred date:</label>
<select name="day" id="date" required="required">
<option value="">Day</option>
<option value="day">1</option>
<option value="day">2</option>
<option value="day">3</option>
<option value='day'>4</option>
<option value='day'>5</option>
<option value='day'>6</option>
<option value='day'>7</option>
<option value='day'>8</option>
<option value='day'>9</option>
<option value='day'>10</option>
<option value='day'>11</option>
<option value='day'>12</option>
<option value='day'>13</option>
<option value='day'>14</option>
<option value='day'>15</option>
<option value='day'>16</option>
<option value='day'>17</option>
<option value='day'>18</option>
<option value='day'>19</option>
<option value='day'>20</option>
<option value='day'>21</option>
<option value='day'>22</option>
<option value='day'>23</option>
<option value='day'>24</option>
<option value='day'>25</option>
<option value='day'>26</option>
<option value='day'>27</option>
<option value='day'>28</option>
<option value='day'>29</option>
<option value='day'>30</option>
<option value='day'>31</option>
</select>
<select name="month" id="date" required="required">
<option value="">Month</option>
<option value='month'>1</option>
<option value='month'>2</option>
<option value='month'>3</option>
<option value='month'>4</option>
<option value='month'>5</option>
<option value='month'>6</option>
<option value='month'>7</option>
<option value='month'>8</option>
<option value='month'>9</option>
<option value='month'>10</option>
<option value='month'>11</option>
<option value='month'>12</option>
</select>
<select name="year" id="date" required="required">
<option value="">Year</option>
<option value='year'>2018</option>
<option value='year'>2019</option>
<option value='year'>2020</option>
<option value='year'>2021</option>
</select></p>
<p><label for="time">Prefered time:</label>
<select name="time" id="time" required="required">
<option value="">Please Select</option>
<option value="time">7:30-8:30</option>
<option value="time">8:30-9:30</option>
<option value="time">9:30-10:30</option>
<option value="time">10:30-11:30</option>
<option value="time">11:30-12:30</option>
<option value="time">12:30-13:30</option>
<option value="time">13:30-14:30</option>
<option value="time">14:30-15:30</option>
<option value="time">15:30-16:30</option>
<option value="time">16:30-17:30</option>
<option value="time">17:30-18:30</option>
<option value="time">18:30-19:30</option>
<option value="time">19:30-20:30</option>
</select></p>
</fieldset>
<fieldset>
<legend>Delivery Information:</legend>
<p><label for="receiver">Receiver Name:</label>
<input type="text" name= "receiver" id="receiver" maxlength="40" size="20" pattern="^[a-zA-Z ]+$" required="required"/></p>
<p><label for="deliveryAddress">Street Address:</label>
<input type="text" name= "deliveryAddress" id="deliveryAddress" maxlength="40" size="30" required="required"/></p>
<p><label for="deliverySuburb">Suburb:</label>
<input type="text" name= "deliverySuburb" id="deliverySuburb" maxlength="40" size="20" required="required"/></p>
<p><label for="state">State:</label>
<select name="state" id="state" required="required">
<option value="">Please Select</option>
<option value="state">VIC</option>
<option value="state">NSW</option>
<option value="state">QLD</option>
<option value="state">NT</option>
<option value="state">WA</option>
<option value="state">SA</option>
<option value="state">TAS</option>
<option value="state">ACT</option>
</select></p>
</fieldset>
<br/>
<input type= "submit" value="Request"/>
</fieldset>
</form>
<p>Home</p>
</body>
</html>
PHP:
<?php
require_once ("settings.php"); //connection info
$conn = #mysqli_connect($host,
$user,
$pwd,
$sql_db
);
$requestID = trim($_POST["requestID"]);
$customerID = trim($_POST["customerID"]);
$requestDate = trim($_POST["requestDate"]);
$description = trim($_POST["description"]);
$weight = trim($_POST["weight"]);
$pickupAddress = trim($_POST["pickupAddress"]);
$pickupSuburb = trim($_POST["pickupSuburb"]);
$date = trim($_POST["date"]);
$time = trim($_POST["time"]);
$receiver = trim($_POST["receiver"]);
$deliveryAddress = trim($_POST["deliveryAddress"]);
$deliverySuburb = trim($_POST["deliverySuburb"]);
$state = trim($_POST["state"]);
$sql_table="Request";
$query = "insert into $sql_table (description, weight, pickupAddress, pickupSuburb, date, time, receiver, deliveryAddress, deliverySuburb, state) values ('$description', '$weight', '$pickupAddress', '$pickupSuburb', '$date', '$time', '$receiver', '$deliveryAddress', '$deliverySuburb', '$state')";
//execute the query -we should really check to see if the batabase exists first.
$result = mysqli_query($conn, $query);
//checks if the exeution was succcessful
if (!$result) {
echo "<p class=\"wrong\">Something is wrong with your request please go back and check your details</p>";
// would not show in a production script
} else {
// display an operation successful message
echo "<p class=\"ok\">Thank you! Your request number is requestID. The cost is <cost>. We will pick-up the item at $time on $date.</p>";
} // if successful query operation
// close the database connection
mysqli_close($conn);
// if successful database connection
?>
I have a similar PHP document to this one which works perfectly. I believe the that I keep getting the message "Something is wrong with your request please go back and check your details" because of the 'date', 'time' or the drop boxes which are 'weight' and 'state' but I tried removing them and nothing changed I kept getting that there was something wrong. I can't seem to figure out what is causing the form to not successfully send. Could someone please try and find the error?
this is my form in which all fields are post on controller page, but only one field is not post on controller page. In this form only 'textbox1' value is not post on controller page, what is problem is their i dont understand please anyone help me to solve this problem
<?php $attributes = 'id="myform"'; ?>
<?php echo form_open_multipart('paidcontroller/submit',$attributes); ?>
<div class="join-left">
<label>Person Name</label>
<input type="text" id="pname" class="required" name="pname" placeholder="anis pathan">
<span id="pnameerror" style="display: none;">Please enter Person Name</span>
<label> Mobile</label>
<input type="text" id="mobile" class="required" name="mobile" placeholder="9111111111">
<span id="mobileerror" style="display: none;">Please enter Mobile No</span>
<span id="validmerror" style="display: none;">Please enter valid mobile no</span>
<label> Email Address</label>
<input type="text" id="email" class="required" name="email" placeholder="#anispathan">
<span id="emailerror" style="display: none;">Please enter email address</span>
<span id="valideerror" style="display: none;">Please enter valid Email</span>
<label>Password</label>
<input type="password" id="passw" class="required" name="passw" placeholder="*********">
<span id="passwerror" style="display: none;">Please enter Password</span>
<label>Confirm Password</label>
<input type="password" id="cpass" class="required" name="cpass" placeholder="*********">
<span id="cpasserror" style="display: none;">Please enter Confirm password</span>
<span id="cmpasserror" style="display: none;">Password do not match with the Confirm Password</span>
<label>Product Category</label>
<?php $attributes = 'id="cat"';
echo form_dropdown('cat', $cat, set_value('cat'), $attributes); ?>
<span id="categoryerror" style="display: none;">Please select category</span>
<label>Company Turnover</label>
<select id="turnover" class="required" name="turnover">
<option value="1~50 Lacs" selected="">1~50 Lacs</option>
<option value="50 Lacs~1 Crore">50 Lacs~1 Crore</option>
<option value="1 Crore~5 Crores">1 Crore~5 Crores</option>
<option value="5 Crores ~ 10 Crores">5 Crores ~ 10 Crores</option>
<option value="10 Crores ~ 20 Crores">10 Crores ~ 20 Crores</option>
<option value="20 Crores ~ 30 Crores">20 Crores ~ 30 Crores</option>
<option value="30 Crores ~ 40 Crores">30 Crores ~ 40 Crores</option>
<option value="40 Crores ~ 50 Crores">40 Crores ~ 50 Crores</option>
<option value="50 Crores and Above">50 Crores and Above</option>
</select>
<span id="turnovererror" style="display: none;">Please select Company Turnover</span>
<label>Company Logo</label>
<input type="file" class="required" id="image" name="image">
<span id="imageerror" style="display: none;">Please select Company Logo</span>
<label>Upload Template</label>
<input type="file" class="required" id="template" name="template">
<span id="temperror" style="display: none;">Please upload Template</span>
</div>
<div class="join-right">
<label>Company Name</label>
<input type="text" id="company_name" class="required" name="company_name" pliceholder="ABC Corporation">
<span id="company_nameerror" style="display: none;">Please enter Company Name</span>
<label>Country</label>
<?php $attributes = 'id="country" class="required"';
echo form_dropdown('country', $country, set_value('country'), $attributes); ?>
<span id="countryerror" style="display: none;">Please select Country</span>
<label>state</label>
<?php $attributes = 'id="state" class="required"';
echo form_dropdown('state', $state, set_value('state'), $attributes); ?>
<span id="stateerror" style="display: none;">Please select state</span>
<label>city</label>
<?php $attributes = 'id="city" class="required"';
echo form_dropdown('city', $city, set_value('city'), $attributes); ?>
<span id="cityerror" style="display: none;">Please select city</span>
<label>Pin/zip Code</label>
<input type="text" id="pin" class="required" name="pin" pliceholder="Pin/zip Code">
<span id="pinerror" style="display: none;">Please enter Pin code</span>
<label>Address</label>
<textarea id="address" name="address" class="required" cols="80" rows="4" wrap="virtual"></textarea>
<span id="addresserror" style="display: none;">Please enter address</span>
<label>Year of Establishment</label>
<select id="year" name="year" class="required">
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
<option value="1899">1899</option>
<option value="1898">1898</option>
<option value="1897">1897</option>
<option value="1896">1896</option>
<option value="1895">1895</option>
<option value="1894">1894</option>
<option value="1893">1893</option>
<option value="1892">1892</option>
<option value="1891">1891</option>
<option value="1890">1890</option>
<option value="1889">1889</option>
<option value="1888">1888</option>
<option value="1887">1887</option>
<option value="1886">1886</option>
<option value="1885">1885</option>
<option value="1884">1884</option>
<option value="1883">1883</option>
<option value="1882">1882</option>
<option value="1881">1881</option>
<option value="1880">1880</option>
<option value="1879">1879</option>
<option value="1878">1878</option>
<option value="1877">1877</option>
<option value="1876">1876</option>
<option value="1875">1875</option>
<option value="1874">1874</option>
<option value="1873">1873</option>
<option value="1872">1872</option>
<option value="1871">1871</option>
<option value="1870">1870</option>
<option value="1869">1869</option>
<option value="1868">1868</option>
<option value="1867">1867</option>
<option value="1866">1866</option>
<option value="1865">1865</option>
<option value="1864">1864</option>
<option value="1863">1863</option>
<option value="1862">1862</option>
<option value="1861">1861</option>
<option value="1860">1860</option>
<option value="1859">1859</option>
<option value="1858">1858</option>
<option value="1857">1857</option>
<option value="1856">1856</option>
<option value="1855">1855</option>
<option value="1854">1854</option>
<option value="1853">1853</option>
<option value="1852">1852</option>
<option value="1851">1851</option>
<option value="1850">1850</option>
<option value="1849">1849</option>
<option value="1848">1848</option>
<option value="1847">1847</option>
<option value="1846">1846</option>
<option value="1845">1845</option>
<option value="1844">1844</option>
<option value="1843">1843</option>
<option value="1842">1842</option>
<option value="1841">1841</option>
<option value="1840">1840</option>
<option value="1839">1839</option>
<option value="1838">1838</option>
<option value="1837">1837</option>
<option value="1836">1836</option>
<option value="1835">1835</option>
<option value="1834">1834</option>
<option value="1833">1833</option>
<option value="1832">1832</option>
<option value="1831">1831</option>
<option value="1830">1830</option>
<option value="1829">1829</option>
<option value="1828">1828</option>
<option value="1827">1827</option>
<option value="1826">1826</option>
<option value="1825">1825</option>
<option value="1824">1824</option>
<option value="1823">1823</option>
<option value="1822">1822</option>
<option value="1821">1821</option>
<option value="1820">1820</option>
<option value="1819">1819</option>
<option value="1818">1818</option>
<option value="1817">1817</option>
<option value="1816">1816</option>
</select>
<div id="TextBoxDiv1">
<label>Textbox #1 : </label>
<input type="text" id="textbox1" class="required">
</div>
<button type="submit" id="add" name="add" value="Submit">ADD PRODUCT</button>
<button type="submit" id="remove" name="remove">REMOVE</button>
</div>
<div class="main-batton">
<button type="submit" id="fill" name="fill" value="Submit">SUBMIT</button>
</div>
<?php form_close(); ?>
this input field is not post on controller page
<div id="TextBoxDiv1">
<label>Textbox #1 : </label>
<input type="text" id="textbox1" class="required">
</div>
this is my jquery validation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var counter = 2;
$("#add").click(function() {
if (counter > 10) {
alert("Only 10 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after('#TextBoxDiv').html('<label>Textbox #' + counter + ' : </label>' +
'<input type="text" class="required" name="textbox' + counter +
'" id="textbox' + counter + '" value="" >');
newTextBoxDiv.appendTo(".join-right");
$('#textbox' + counter).rules("add", {
required: true
})
counter++;
});
$("#remove").click(function() {
if (counter == 1) {
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$('#fill').click(function() {
$("#myform").submit();
});
$.validator.addMethod("requiredCountry", function(element) {
return ( $("#country").val() !='0' );
}, "Please select country.");
$.validator.addMethod("requiredState", function(element) {
return ( $("#state").val() !='0' );
}, "Please select State.");
$.validator.addMethod("requiredCity", function(element) {
return ( $("#city").val() !='0' );
}, "Please select City.");
$("#myform").validate({
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
pname: "required",
company_name: "required",
email: {
required: true,
email: true
},
mobile: {
required: true
},
passw: {
required: true,
minlength: 5
},
cpass: {
required: true,
minlength: 5,
equalTo: "#passw"
},
country: {
requiredCountry : true
},
state: {
requiredState : true
},
city: {
requiredCity : true
},
address: {
required: true
},
pin: {
required: true,
minlength: 6
}
},
// Specify validation error messages
messages: {
pname: "Please enter your Person Name",
company_name: "Please enter your Company Name",
passw: {
required: "Please enter a password",
minlength: "Password must be at least 5 characters"
},
cpass: {
required: "Please enter a confirm password",
minlength: "Password must be at least 5 characters",
equalTo: "Please enter same password as above"
},
mobile: {
required: "Please enter a Mobile No"
},
email: {
required: "Please enter email address",
email: "Please enter a valid email address."
},
address: {
required: "Please enter Address"
},
pin: {
required: "Please enter pin code",
minlength: "Pin code must be six digit"
},
}
});
});
</script>
please anyone help me to solve this problem.
Your input field is missing the "name" attribute, so it won't be posted:
<div id="TextBoxDiv1">
<label>Textbox #1 : </label>
<input type="text" id="textbox1" name="textbox1" class="required">
</div>
Before anyone yells Repost, there aren't many cases like mine that I've seen.I have a contact form that has the possibility to have a main Select option, a sub-Select option and then a sub-Select option of that one. Overall, There are 27 options to choose from and I think I could make the php give me all 27 of those and then do a "yes they selected this one but not that one" type of report, but I digress.How do I have the php script for my contact form send only what is selected from a possible three-tiered select menu? EDIT: I'm totally willing to use something other than PHP to help facilitate this, I just need help with the PHP script as well.Edit: To be clear, I'm try to create and populate a php script, not valdiate the form/check that all required sections are filled out.Code
<form action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option>Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option>Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option>Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option>Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
</form>
I assume that you do have jquery to display the relevant select boxes upon selection of devices etc... I have made a few changes in your html form, like adding id="form" in your form tag. Also added value="" for options like "Please select Service".. Here is the code. Hope this helps.. Refer to this as well..
Jquery form submit to check empty fields
<form id="form" action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option value="">Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option value="">Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option value="">Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option value="">Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('select').change(function(){
var boxid = $(this).children('option:selected').attr('data-target');
alert(boxid);
if(boxid == "devices") {
var divId = "service-" + boxid;
}
document.getElementById(divId).style.display = "block";
});
$("form").submit(function(){
// $(':input[value=""]').attr('disabled', true);
$("input[type='text'],select,input[type='password'],textarea",this).each(function() {
if($(this).val().trim() == "") {
$(this).attr('disabled', true);
}
})
});
});
</script>
Below is a snippet of the code I have created on a form page. The form inputs display the correct variables for $adjustedGrossIncome, $personalExemptions and the calculation for Tax Due Before Refundable Credits, but when I try to echo $birthYear the php dies. Any hints what I'm doing wrong?
<?php
$filingStatus = $_Post['filingStatus'];
$birthYear = $_Post['birthYear'];
$dependents = $_Post['dependents'];
$children = $_POST['children'];
$exemptions = $_POST['exemptions'];
$income = $_POST['income'];
$investments = $_POST['investments'];
$retirement = $_POST['retirement'];
$property = $_POST['property'];
$adjustedGrossIncome = $income + $investments + $retirement;
$personalExemptions = ($exemptions * 3950);
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset style="width:500px;">
<legend>Filing Status</legend>
<p>
<label>
<input type="radio" name="filingStatus" value="married" id="filingStatus" />
Married filing jointly</label>
<br />
<label>
<input type="radio" name="filingStatus" value="single" id="filingStatus" />
Single or Head of Household</label>
</p>
</fieldset>
<p>
<label>Birth Year
<select name="birthYear" id="birthYear">
<option>Select Year</option>
<option value="1923">1923</option>
<option value="1924">1924</option>
<option value="1925">1925</option>
<option value="1926">1926</option>
<option value="1927">1927</option>
<option value="1928">1928</option>
<option value="1929">1929</option>
<option value="1930">1930</option>
<option value="1931">1931</option>
<option value="1932">1932</option>
<option value="1933">1933</option>
<option value="1934">1934</option>
<option value="1935">1935</option>
<option value="1936">1936</option>
<option value="1937">1937</option>
<option value="1938">1938</option>
<option value="1939">1939</option>
<option value="1940">1940</option>
<option value="1941">1941</option>
<option value="1942">1942</option>
<option value="1943">1943</option>
<option value="1944">1944</option>
<option value="1945">1945</option>
<option value="1946">1946</option>
<option value="1947">1947</option>
<option value="1948">1948</option>
<option value="1949">1949</option>
<option value="1950">1950</option>
<option value="1951">1951</option>
<option value="1952">1952</option>
<option value="1953">1953</option>
<option value="1954">1954</option>
<option value="1955">1955</option>
<option value="1956">1956</option>
<option value="1957">1957</option>
<option value="1958">1958</option>
<option value="1959">1959</option>
<option value="1960">1960</option>
<option value="1961">1961</option>
<option value="1962">1962</option>
<option value="1963">1963</option>
<option value="1964">1964</option>
<option value="1965">1965</option>
<option value="1966">1966</option>
<option value="1967">1967</option>
<option value="1968">1968</option>
<option value="1969">1969</option>
<option value="1970">1970</option>
<option value="1971">1971</option>
<option value="1972">1972</option>
<option value="1973">1973</option>
<option value="1974">1974</option>
<option value="1975">1975</option>
<option value="1976">1976</option>
<option value="1977">1977</option>
<option value="1978">1978</option>
<option value="1979">1979</option>
<option value="1980">1980</option>
<option value="1981">1981</option>
<option value="1982">1982</option>
<option value="1983">1983</option>
<option value="1984">1984</option>
<option value="1985">1985</option>
<option value="1986">1986</option>
<option value="1987">1987</option>
<option value="1988">1988</option>
<option value="1989">1989</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
</select>
</label>
</p>
<p>
<label>Number of Dependents (not including taxpayer and spouse if applicable
<input type="text" name="dependents" id="dependents" />
</label>
</p>
<p>
<label>Number of Children under 18
<input type="text" name="children" id="children" />
</label>
</p>
<p>
<label>Total number of exemptions
<input type="text" name="exemptions" id="exemptions" />
</label>
</p>
<p>
<label>Total Wages/Salary
<input type="text" name="income" id="income" />
</label>
</p>
<p>
<label>Investment income (interest, dividends, capital gains)
<input type="text" name="investments" id="investments" />
</label>
</p>
<p>
<label>Retirement income (pension, IRA, 401(k), etc.)
<input type="text" name="retirement" id="retirement" />
</label>
</p>
<p>
<label>Annual property taxes paid on primary residence and/or annual rent
<input type="text" name="property" id="property" />
</label>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Calculate Net Tax Liability for 2013" />
<input type="reset" name="reset" id="reset" value="Reset Form" onClick="window.location.reload()" />
</p>
</form>
<p>Adjusted Gross Income: $<?php echo($adjustedGrossIncome); ?></p>
<p>Personal Exemptions: $<?php echo($personalExemptions); ?></p>
<p>Tax Due Before Refundable Credits: $<?php echo(($adjustedGrossIncome - $personalExemptions) * .0425); ?></p>
<p><?php echo($birthYear); ?></p>
Change all $_Post to uppercase $_POST
This is known as a superglobal and must be in uppercase.
More on superglobals can be found on the PHP.net Web site
http://php.net/manual/en/language.variables.superglobals.php