Only show list option based on earlier form choice - php

Here's part of my form:
<label for="User">Select your account type:</label>
<select name="usertype" for="usertype" id="usertype" required>
<option value="1">Employee</option>
<option value="2">Manager</option>
</select>
<label for="User">Select the company you work for:</label>
<select name="company" for="company" id="company" required>
<?php
include ('processors/generate-company-list.php');
?>
<option value="NULL">I'll create my own company later</option>";
</select>
I only want <option value="NULL">I'll create my own company later</option> to be available if they choose to be a manager earlier in the form. Is this possible?

<script type="text/javascript">
function check(){
var usertype=document.getElementById("usertype").value;
if(usertype==2){
document.getElementById("company").selectedIndex = "0";
document.getElementById("company").disabled=true;
}else{
document.getElementById("company").disabled=false;
}
}
</script>
<label for="User">Select your account type:</label>
<select name="usertype" for="usertype" id="usertype" required onchange='check();'>
<option value="1">Employee</option>
<option value="2">Manager</option>
</select>
<label for="User">Select the company you work for:</label>
<select name="company" for="company" id="company" required>
<?php
include ('processors/generate-company-list.php');
?>
<option value="NULL">I'll create my own company later</option>";
<option value="1"> listitem1 </option>";
<option value="1"> listitem2</option>";
</select>
I used javascript function to select 0 index whenever manager is selected and disabled second select box.

Related

Creating a dynamic form in php

I am trying to create a dynamic HTML form where the fields displayed are based on inputs in the field above it. So far, I have only found resources that work in JS but I was wondering if there was a pure PHP way to do it.
To give some context: I would like to create a form for a user to set their goal. The 'How Much' and 'programme duration' fields are dependent on the 'goal type' field. Ie. if They choose a muscle building goal then it will only show 5% etc. Here is my code so far...
Much appreciated in advanced!
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
session_start();
if (isset($_SESSION['Username'])) {
?>
<html>
<head>
</head>
<body>
<h1>Please set your goal and programme type</h1>
<form method="POST" action="Set_Goal_process.php" >
<label for="Sex"><b>Sex: </b></label>
<select name="Sex" id="Sex" required>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<label for="Age"><b>Age: </b></label>
<input type="number" name="Age" id="Age" value="Age" required>
<label for="Height"><b>Height: </b></label>
<input type="number" name="Height" id="Height" required>
<label for="Current Weight"><b>Current Weight: </b></label>
<input type="number" name="Initial_weight" id="Initial Weight" required>
<br><br><br><br><br><br><br><br><br>
<label for="Activity level"><b>Activity level: </b></label>
<select name="Activity_level" id="Activity level" required>
<option value=1>Sedentary</option>
<option value=2>Mostly sedentary</option>
<option value=3>Lightly active</option>
<option value=4>Highly active</option>
</select>
<label for="Goal type"><b>Goal type: </b></label>
<select name="Goal_type" id="Goal type" required>
<option value=1>Fat Loss</option>
<option value=2>Maintenance</option>
<option value=3>Muscle Building</option>
</select>
<label for="How much"><b>How much: </b></label>
<select name="How_much" id="How much" default="0" required>
<option value=-10>-10%</option>
<option value=-7.5>-7.5%</option>
<option value=-5>-5%</option>
<option value=-2.5>-2.5%</option>
<option value=0 selected>0%</option>
<option value=2.5>2.5%</option>
<option value=5>5%</option>
</select>
<!-- comment make both How much and program duration conditional -->
<label for="Program Duration"><b>Program Duration: </b></label>
<select name="Program_duration" id="Program Duration" required>
<option value=4>4 weeks</option>
<option value=8>8 weeks</option>
<option value=12 selected>12 weeks</option>
</select>
<label for="Experience_level"><b>Experience level: </b></label>
<select name="Expereince_level" id="Expereince level" required>
<option value=1 selected>Beginner</option>
<option value=2>Novice</option>
<option value=3 >Intermediate</option>
<option value=4 >Advanced</option>
</select>
<label for="Sessions per week">Sessions per week:</label>
<input type="number" name="Sessions_per_week" id="Sessions per week" min="1" max="7" required>
<label for="Start date">Start date:</label>
<input type="date" name="Start date"id="Start date" >
<br><br>
<input type="submit" name="Submit" value="Get Started!"required>
</form>
</body>
</html>
<?php
}else {
session_destroy();
header("location: index.php");
}

Is there any way to write PHP code inside .twig file in WordPress? I am trying to send a mail by using the form values from a .twig template file

Is there any way to write PHP code inside .twig file in WordPress? I am trying to send a mail by using the form values from a .twig template file.
page-pledgeform.twig
{% extends "base.twig" %}
{% block content %}
<body class="{{body_class}}">
<div class="wrapper">
<section id="content" role="main" class="content-wrapper">
{% block body %}
<!-- strat_body_content -->
<div class="body_content">
<div class="space_height"></div>
<div class="form_section">
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<!-- Top Navigation -->
<div class="main clearfix">
<form id="nl-form" method="POST" action="" class="nl-form">
I am <input type="text" name="name" id="user_name" value="" placeholder="Name" data-subline="For example: <em>Mr. K. Roy</em>"/>
It is a long <input type="text" value="" placeholder="Country name" data-subline="For example:
<em>India</em>"/>
Gender
<select>
<option value="1" selected>Male</option>
<option value="2">Female</option>
<option value="3">Other</option>
</select>
Lorem
<select>
<option value="1" selected>O</option>
<option value="2">B</option>
<option value="3">B+</option>
<option value="4">B-</option>
<option value="2">A-</option>
</select>
.
There are many <input type="text" value="" placeholder="Address" data-subline="For example: <em>Los Angeles</em> or <em>New York</em>"/>
passages of
<select>
<option value="1" selected>Mumbai</option>
<option value="2">Delhi</option>
<option value="3">Bangalore</option>
<option value="4">Hyderabad</option>
<option value="5">Ahmedabad</option>
<option value="6">Kolkata</option>
</select>
classical Latin
<select>
<option value="1" selected>Gujarat</option>
<option value="2">Andhra Pradesh</option>
<option value="3">Tamil Nadu</option>
<option value="4">Maharashtra</option>
<option value="5">West Bengal</option>
</select>
first true
<select>
<option value="1" selected>Vijayawada</option>
<option value="2">Kanyakumari</option>
<option value="3">Rewalsar</option>
<option value="4">Dehradun</option>
<option value="2">24 parganas</option>
</select>
There are many <input type="text" value="" placeholder="Pin code" data-subline="For example: <em>700049</em>"/>
There are <input type="email" value="" placeholder="Email ID" data-subline="For example: <em>mac#gmail.com</em>"/>
Phone <input type="number" value="" placeholder="Phone Number" data-subline="For example: <em>000-123-000</em>"/>
Mobile number <input type="number" value="" placeholder="Mobile Number" data-subline="For example: <em>000-123-000</em>"/>
My information may be shared with the
<select>
<option value="1" selected>Yes</option>
<option value="2">No</option>
</select>
<div class="nl-overlay"></div>
<br><br><br>
<h4>Emergency Contact Person Details :-</h4>
I am <input type="text" name="name" value="" placeholder="Name" data-subline="For example: <em>Mr. k. Roy</em>"/>
It is a long <input type="text" value="" placeholder="Country name" data-subline="For example: <em>India</em>"/>
Gender
<select>
<option value="1" selected>Male</option>
<option value="2">Female</option>
<option value="3">Other</option>
</select>
Lorem
<select>
<option value="1" selected>O</option>
<option value="2">B</option>
<option value="3">B+</option>
<option value="4">B-</option>
<option value="2">A-</option>
</select>
.
There are many <input type="text" value="" placeholder="Address" data-subline="For example: <em>India</em>"/>
passages of
<select>
<option value="1" selected>Mumbai</option>
<option value="2">Delhi</option>
<option value="3">Bangalore</option>
<option value="4">Hyderabad</option>
<option value="5">Ahmedabad</option>
<option value="6">Kolkata</option>
</select>
classical Latin
<select>
<option value="1" selected>Gujarat</option>
<option value="2">Andhra Pradesh</option>
<option value="3">Tamil Nadu</option>
<option value="4">Maharashtra</option>
<option value="5">West Bengal</option>
</select>
first true
<select>
<option value="1" selected>Vijayawada</option>
<option value="2">Kanyakumari</option>
<option value="3">Rewalsar</option>
<option value="4">Dehradun</option>
<option value="2">24 parganas</option>
</select>
There are many <input type="text" value="" placeholder="Pin code" data-subline="For example: <em>700049</em>"/>
There are <input type="email" value="" placeholder="Email ID" data-subline="For example: <em>mac#gmail.com</em>"/>
Phone <input type="number" value="" placeholder="Phone Number" data-subline="For example: <em>000-123-000</em>"/>
Mobile number <input type="number" value="" placeholder="Mobile Number" data-subline="For example: <em>000-123-000</em>"/>
My information may be shared with the
<select>
<option value="1" selected>Yes</option>
<option value="2">No</option>
</select>
<div class="clearfix"></div>
<div class="nl-submit-wrap" style="float: right;">
<button class="nl-submit" name="submit" id="btnSubmit" type="submit">Agree & Submit</button>
</div>
<div class="clearfix"></div>
<div class="nl-overlay"></div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extrajs %}
<script src="{{theme.link}}/js/nlform.js"></script>
<script>
var nlform = new NLForm( document.getElementById( 'nl-form' ) );
</script>
<script>
var emargency = new NLForm( document.getElementById( 'emargency' ) );
</script>
{% endblock %}
</div>
</body>
</html>
{% endblock %}
twig is not like blade, you can't write php code inside.
However, you can write your own twig extensions:
https://symfony.com/doc/current/templating/twig_extension.html
please be sure to separate your twig extension from your logic (send mail), add this functionality on a service and bridge both (service & twig extension).

I need to keep the values entered by a user after refreshing the webpage

I have created a form entry web page to store the data entered to a local database . The only problem is that after the submit button is clicked on the form it goes to another file named "info1.php" to store the data in the local database , in that file it also validates if the entered data is valid for example the email . If the data is invalid it refreshes the page to the form entry site or web page "home.php"
It would be much better the same user does not have to enter the whole thing again from the start , But instead the same value previously entered still resides in the web page (ie) form Thanks in Advance guys :-)
The form code is :
<?php
session_start();
?>
<head>
<php
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Entry Form</title>
<link rel="stylesheet" href="css/normalize.css">
<link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<form action="info1.php" method="post">
<h1>DATA ENTRY</h1>
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="user_name" required/>
<label for="rollnumber">Roll number</label>
<input type="text" id="rollnum" name="roll_number" required/>
<label for="batch">Batch</label>
<select id="batch" name="user_batch" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="2013-2017">2013-2017</option>
<option value="2014-2018">2014-2018</option>
<option value="2015-2019">2015-2019</option>
<option value="2016-2020">2016-2020</option>
</select>
</fieldset>
<label for="from">Came from</label>
<select id="from" name="user_from" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="+2">+2</option>
<option value="Diploma">Diploma</option>
</select>
<label for="year">Year</label>
<select id="year" name="user_year" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label for="level">Level</label>
<select id="level" name="user_level"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="UG">UG</option>
<option value="PG">PG</option>
</select>
<label for="email">Email:</label>
<input type="text" id="email_id" name="email_id" required/>
<label for="name">Father`s Name:</label>
<input type="text" id="fname" name="F_name" required/>
<label for="name">Mother`s Name:</label>
<input type="text" id="mname" name="m_name" required/>
<label for="name">Guardian`s Name:</label>
<input type="text" id="gname" name="g_name" >
<label for="mob_number">Students Mobile Number</label>
<input type="number" id="mob_number" name="mob_number"required/>
</select>
<label for="addressline1">Address Line 1</label>
<input type="text" id="addressline1" name="addressline1" required/>
</select>
<label for="addressline2">Address Line2</label>
<input type="text" id="addressline2" name="addressline2" required/>
</select>
<label for="city">City</label>
<input type="text" id="city" name="city" required/>
<label for="pmobnumber">Parents Mobile Number</label>
<input type="number" id="pmob_num" name="pmob_number" required/>
<label for="landnumber">LandLine Number or Parents Number</label>
<input type="number" id="landnum" name="land_number"required/>
<label for="cutoff">+2 cutoff</label>
<input type="number" id="cutoff" name="cutoff">
<label for="dept">Department</label>
<select id="dept" name="dept" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="CSE">CSE</option>
<option value="IT">IT</option>
<option value="ECE">ECE</option>
<option value="EEE">EEE</option>
<option value="MECH">MECH</option>
<option value="CIVIL">CIVIL</option>
</select>
<label for="medium">Medium of Instruction</label>
<select id="medium" name="medium"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="ENGLISH">English</option>
<option value="TAMIL">Tamil</option>
</select>
<label for="locality">Locality</label>
<select id="locality" name="locality"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="RURAL">Rural</option>
<option value="URBAN">Urban</option>
</select>
<label for="intrest">Intrested In</label>
<select id="intrest" name="intrest"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="PLACEMENTS">Placements</option>
<option value="HIGHER STUDIES">Higher Studies</option>
<option value="Entrepreneurship">Entrepreneurship</option>
</select>
<label for="scholar">Scholarship</label>
<select id="scholar" name="scholar"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="GOVERNMENT">Government</option>
<option value="PRIVATE">Private</option>
</select>
<label for="income">Parents Annual Income</label>
<select id="income" name="income" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="Less than 50,000">Less than 50,000</option>
<option value="Less than 1,00,000">Less than 1,00,000</option>
<option value="Less than 2,00,000">Less than 2,00,000</option>
<option value="Less than 5,00,000">Less than 5,00,000</option>
<option value="Less than 10,00,000">Less than 10,00,000</option>
<option value="OTHERS">others</option>
</select>
<label for="year">Caste</label>
<select id="caste" name="user_caste" required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="OC">OC</option>
<option value="BC">BC</option>
<option value="MBC">MBC</option>
<option value="BCM">BCM</option>
<option value="SC">SC</option>
<option value="ST">ST</option>
</select>
<label for="admit">Admitted through</label>
<select id="admit" name="user_admit"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="Government Quota">Government Quota</option>
<option value="Manegement Quota">Manegement Quota</option>
</select>
<label for="stay">Staying In</label>
<select id="stay" name="user_stay"required/>
<option value="NoneSelected">---Click to Select---</option>
<option value="With parents">With parents</option>
<option value="College Hostel">College Hostel</option>
<option value="Outside Room">Outside Room</option>
</select>
</fieldset>
<button type="submit" onclick="phonenumber(pmob_number)">ENTER DATA</button>
</form>
<script src="js/mob_valid.js"></script>
</body>
The code for the file info1.php is:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$conn = mysqli_connect ($servername , $username , $password) or die("unable to connect to host");
$sql = mysqli_select_db ($conn,'vcet') or die("unable to connect to database");
//code to insert into db...
$user_name=$_POST['user_name'];
$roll_number=$_POST['roll_number'];
$user_batch=$_POST['user_batch'];
$user_from=$_POST['user_from'];
$user_year=$_POST['user_year'];
$user_level=$_POST['user_level'];
$email_id=$_POST['email_id'];
$F_name=$_POST['F_name'];
$m_name=$_POST['m_name'];
$g_name=$_POST['g_name'];
$mob_number=$_POST['mob_number'];
$addressline1=$_POST['addressline1'];
$addressline2=$_POST['addressline2'];
$city=$_POST['city'];
$pmob_number=$_POST['pmob_number'];
$land_number=$_POST['land_number'];
$cutoff=$_POST['cutoff'];
$dept=$_POST['dept'];
$medium = $_POST['medium'];
$locality=$_POST['locality'];
$intrest=$_POST['intrest'];
$scholar=$_POST['scholar'];
$income=$_POST['income'];
$user_caste=$_POST['user_caste'];
$user_admit=$_POST['user_admit'];
$user_stay=$_POST['user_stay'];
if (!filter_var($email_id, FILTER_VALIDATE_EMAIL)) {
echo '<script language="javascript">';
echo 'alert("Sorry...You entered an invalid email id..!!!")';
echo '</script>';
//mysqli_query("delete from studentinfo where roll_number='$roll_number'");
header( "refresh:1;url=http://localhost/DB/home.php" );
}else
{
//executes the rest of the code
$mob_number1=$mob_number;
if(!preg_match('/^\d{10}$/',$mob_number1)) // phone number is valid
{
echo '<script language="javascript">';
echo 'alert("Sorry...You entered a wrong Mobile number..!!!")';
echo '</script>';
//mysqli_query("delete from studentinfo where roll_number='$roll_number'");
header( "refresh:1;url=http://localhost/DB/home.php" );
}
else // phone number is valid
{
$msg="";
$num_length = strlen((string)$pmob_number);
if($num_length!=10){
echo '<script language="javascript">';
echo 'alert("Sorry...You entered a wrong Mobile number..!!!")';
echo '</script>';
//mysqli_query("delete from studentinfo where roll_number='$roll_number'");
header( "refresh:1;url=http://localhost/DB/home.php" );
}else
{
$user_info = "INSERT INTO studentinfo"." (user_name,roll_number,user_batch,user_from,user_year,user_level,email_id,F_name,m_name,g_name,mob_number,addressline1,addressline2,city,pmob_number,land_number,cutoff,dept,medium,locality,intrest,scholar,income,user_caste,user_admit, user_stay)". "VALUES ('$user_name', '$roll_number','$user_batch','$user_from','$user_year','$user_level','$email_id','$F_name','$m_name','$g_name','".$mob_number."','$addressline1','$addressline2','$city','$pmob_number','$land_number','$cutoff','$dept','$medium','$locality','$intrest','$scholar','$income','$user_caste','$user_admit','$user_stay')";
if (!mysqli_query($conn,$user_info)) { die('Error: ' . mysqli_error($conn)); } echo '<script language="javascript">';
echo 'alert("Awesome!! your INFORMATION was added to the DATABASE")';
echo '</script>';
header( "refresh:1;url=http://localhost/DB/home.php" );
mysqli_close($conn);
}
}
}
?>
As RiggsFolly said in the comments, you could use the SESSION to keep the values, to use a SESSION variable, you have to open the session at the beginning of each file where you'll use it.
Basically, on your form page : ( you should ofc check if the $_SESSION['input_value'] var exists )
<?php session_start();
if(!isset($_SESSION['input_value']) {
$_SESSION['input_value'] = "Default value for this input";
}
?>
some code ...
<input value='<?php echo $_SESSION['input_value']; ?>'>
on your form treatment page :
<?php session_start();
some code ...
$_SESSION['input_value'] = $_POST['input_value']; // ( or $_GET['input_value'] )
?>

How should I make the php script for a contact form from multiple select dependencies

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>

How to call data with variables that we want

I'm creating a system which provide a report generator, now my problem is i dont know how to call data with the variables that i want. For example I only want the data from January // 2014 // from the account department and so on. Now, i don't know what code to show but below is the menu where user select their variables
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function showForm() {
var selopt = document.getElementById("opts").value;
if (selopt == "Tenaga Nasional Berhad") {
document.getElementById("f1").style.display = "block";
document.getElementById("f2").style.display = "none";
}
if (selopt == "Telekom Malaysia") {
document.getElementById("f2").style.display = "block";
document.getElementById("f1").style.display = "none";
}
if (selopt == 0) {
document.getElementById("f2").style.display = "none";
document.getElementById("f1").style.display = "none";
}
}
</script>
<div id="contact_form">
<h4>Pilih Ketetapan Laporan</h4>
<form method="post" name="pilih_kategori_daftar">
<label for="daerah">Daerah:</label>
<select class="required input_field" name="daerah" id="daerah" required/>
<option value="">--Pilih Daerah--</option>
<option value="Kuantan">Kuantan</option>
<option value="Maran">Maran</option>
<option value="Bentong">Bentong</option>
<option value="Raub">Lipis</option>
<option value="Jerantut">Jerantut</option>
<option value="Cameron Highlands">Cameron Highlands</option>
<option value="P.Tenggara">Pahang Tenggara</option>
<option value="Pekan">Pekan</option>
<option value="Rompin">Rompin</option>
<option value="Temerloh">Temerloh</option>
<option value="Bera">Bera</option>
<option value="Ibu Pejabat">Ibu Pejabat</option>
</select>
<div class="cleaner_h10"></div>
<label for="bulan_bill">Bulan</label>
<select class="required bill_caj" name="bulan_bill" id="bulan_bill" width="300px" required/>
<option value="">--Pilih Bulan--</option>
<option value="Januari">Januari</option>
<option value="Februari">Februari</option>
<option value="Mac">Mac</option>
<option value="April">April</option>
<option value="Mei">Mei</option>
<option value="Jun">Jun</option>
<option value="Julai">Julai</option>
<option value="Ogos">Ogos</option>
<option value="September">September</option>
<option value="Oktober">Oktober</option>
<option value="November">November</option>
<option value="Disember">Disember</option>
</select>
<div class="cleaner_h10"></div>
<label for="tahun_bill">Tahun</label>
<input type="text" maxlength="4" size="4" id="tahun_bill" name="tahun_bill" class="required year_field" placeholder="Tahun" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required/>
<div class="cleaner_h10"></div>
<label for="kategori_akaun">Kategori</label>
<select id="opts" onchange="showForm()" class="input_field" required>
<option value="0">--Pilih Kategori--</option>
<option value="Tenaga Nasional Berhad">Akaun TNB</option>
<option value="Telekom Malaysia">Akaun TM</option>
</select>
<div class="cleaner_h10"></div>
<div id="f1" style="display:none">
<form name="akaun_tnb">
<label for="jenis">Jenis Akaun</label>
<select id="opts" onchange="showForm()"class="input_field">
<option value="0">--Pilih Jenis Akaun--</option>
<option value="Rumah Pam">Rumah Pam</option>
<option value="Loji Air">Loji Air</option>
<option value="Stor">Stor</option>
</select>
</form>
</div>
<div id="f2" style="display:none">
<form name="akaun_tm">
<label for="jenis">Jenis Akaun</label>
<select id="opts" onchange="showForm()"class="input_field">
<option value="0">--Pilih Jenis Akaun--</option>
<option value="Telefon">Telefon</option>
<option value="Telefon/Streamyx">Telefon/Streamyx</option>
<option value="Streamyx">Streamyx</option>
<option value="SMS Blast">SMS Blast</option>
<option value="TM NET">TM NET</option>
</select>
</form>
</div>
</form>
</div>
search in google:
1, How to create mysqli database, tables, columns.
2, PHP, how to connect, extract, insert data from mysqli using php,
3. How to echo mysqli data into html, 4. how to submit form to php and insert data to mysqli, 5. Learn to use AJAX & JSON...this you may leave for few months:)

Categories