I am trying to create a simple form that will send data to a PHP script upon submitting the form. I am able to access all of the textbox values, and have successfully implemented variables for each of them. However, when I try to access the value of a combo box on my form, I get this error in the PHP:
Notice: Undefined index: cmbProvince in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 15
HTML
<form id="orderForm" action="scripts/index.php" method="post" onsubmit="return validateForm()">
<fieldset id="customerInfo">
<legend>Customer Information</legend>
<label for="txtFirstName">Name:</label><br>
<input type="text" id="txtFirstName" name="txtFirstName"
placeholder="First Name" autofocus="true"
oninput="formatFirstName()">
<input type="text" id="txtLastName" name="txtLastName"
placeholder="Last Name" oninput="formatLastName()"><br><br>
<label for="txtAddress">Address:</label><br>
<input type="text" id="txtAddress" name="txtAddress" placeholder="Address"
oninput="formatAddress()"><br>
<input type="text" id="txtCity" name="txtCity" placeholder="City"
oninput="formatCity()">
<select id="cmbProvince" name="cmbProvince">
<option value="on">ON</option>
<option value="qc">QC</option>
<option value="mb">MB</option>
<option value="sk">SK</option>
<option value="ab">AB</option>
<option value="bc">BC</option>
<option value="nb">NB</option>
<option value="nl">NL</option>
<option value="ns">NS</option>
<option value="nu">NU</option>
<option value="pe">PE</option>
<option value="nt">NT</option>
<option value="yt">YT</option>
</select><br>
<input type="text" id="txtPostalCode" name="txtPostalCode"
placeholder="Postal Code" oninput="displayPostalCode()">
<br><br>
<!-- Button that will display the order form -->
<input type="button" id="btnOrder" value="Order"
onclick="showOrderInformation()">
</fieldset><br>
<fieldset id="orderInfo">
<legend>Order Information</legend>
<label for="cmbProduct">Product:</label><br>
<select id="cmbProduct">
<option> -- Select -- </option>
<option>Blackberries</option>
</select>
#
<input type="number" id="txtQuantity" name="txtQuantity" value="1"
step="1" min="1" max="50" oninput="displayTotalTax()"><br><br>
</fieldset>
<br><br>
<!-- Button to submit the form to PHP after validation -->
<input type="submit" id="btnSubmit" value="Submit">
</form>
PHP (lines 10 - 19)
/* Capture the user input from the HTML form */
$strFirstName = $_POST['txtFirstName'];
$strLastName = $_POST['txtLastName'];
$strAddress = $_POST['txtAddress'];
$strCity = $_POST['txtCity'];
$strProvince = $_POST['cmbProvince'];
$strPostalCode = $_POST['txtPostalCode'];
Am I typing something wrong? Or missing something? Everything except the combo box is working.
Let me know if I need to include anything else. Thanks!
EDIT
Here is what happens when I try var_dump($_POST);:
Notice: Undefined index: cmbProvince in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 15
Notice: Undefined index: cmbProduct in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 18
array(6) { ["txtFirstName"]=> string(7) "Kendall"
["txtLastName"]=> string(4) "Roth"
["txtAddress"]=> string(19) "22 Resolution Drive"
["txtCity"]=> string(8) "Millbank"
["txtPostalCode"]=> string(7) "K2K 2K2"
["txtQuantity"]=> string(1) "2" }
Your code works for me with a little bit changes, try this:
<form id="orderForm" action="scripts/index.php" method="post" onsubmit="return validateForm()">
<fieldset id="customerInfo">
<legend>Customer Information</legend>
<label for="txtFirstName">Name:</label><br>
<input type="text" id="txtFirstName" name="txtFirstName"
placeholder="First Name" autofocus="true"
oninput="formatFirstName()">
<input type="text" id="txtLastName" name="txtLastName"
placeholder="Last Name" oninput="formatLastName()"><br><br>
<label for="txtAddress">Address:</label><br>
<input type="text" id="txtAddress" name="txtAddress" placeholder="Address"
oninput="formatAddress()"><br>
<input type="text" id="txtCity" name="txtCity" placeholder="City"
oninput="formatCity()">
<select id="cmbProvince" name="cmbProvince">
<option value="on">ON</option>
<option value="qc">QC</option>
<option value="mb">MB</option>
<option value="sk">SK</option>
<option value="ab">AB</option>
<option value="bc">BC</option>
<option value="nb">NB</option>
<option value="nl">NL</option>
<option value="ns">NS</option>
<option value="nu">NU</option>
<option value="pe">PE</option>
<option value="nt">NT</option>
<option value="yt">YT</option>
</select><br>
<input type="text" id="txtPostalCode" name="txtPostalCode"
placeholder="Postal Code" oninput="displayPostalCode()">
<br><br>
<!-- Button that will display the order form -->
<input type="button" id="btnOrder" value="Order"
onclick="showOrderInformation()">
</fieldset><br>
<fieldset id="orderInfo">
<legend>Order Information</legend>
<label for="cmbProduct">Product:</label><br>
<select id="cmbProduct" name="cmbProduct"> //changes is in this code
<option> -- Select -- </option>
<option value="Blackberries">Blackberries</option>
</select>
#
<input type="number" id="txtQuantity" name="txtQuantity" value="1"
step="1" min="1" max="50" oninput="displayTotalTax()"><br><br>
</fieldset>
<br><br>
<!-- Button to submit the form to PHP after validation -->
<input type="submit" id="btnSubmit" value="Submit">
</form>
In your index.php write:
<?php
if(isset($_POST) && !empty($_POST)){
echo "<pre/>";print_r($_POST);die;
}
?>
Output:-
Array
(
[txtFirstName] => a
[txtLastName] => b
[txtAddress] => c
[txtCity] => d
[cmbProvince] => qc
[txtPostalCode] => e
[cmbProduct] => Blackberries
[txtQuantity] => 1
)
Kendall, you were:
missing name for your <select id="cmbProduct">, and
missing value for your cmbProduct options as well
Putting in 'disabled selected' is a good practice as well as people won't be able to select the 'select' option :)
Your code
<select id="cmbProduct">
<option> -- Select -- </option>
<option>Blackberries</option>
</select>
Correct code
<select id="cmbProduct" name="cmbProduct>
<option value="select" disabled selected> -- Select -- </option>
<option value="blackberries">Blackberries</option>
</select>
Related
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.
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 have a system which has only two transaction, Registration.php and req.php. The two transaction data are saved in the table new in my database. Registration.php is my first transacton, then req.php. This php files are form, which both has a submit button linked to add.php. The fields of my new table are devided in the two forms. The flow is that first Registration.php will be executed then req.php. My table new has a primary key named new_id and its auto increment. My problem is that, after execution of both forms, ONLY the data of Registration.php are save in the database table new and the req.php are blank. What is the problem? I need your help.
here is the Registration.php code:
<html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js">
</script>
<TITLE>
New Registration Form
</TITLE></head>
<body>
<center>
<br>
<p style="font-weight: bold; font-size: 30">Please Fill Out Your Information Sheet</p><p><?php
echo date('F j, Y, g:i a', time()+25200);
?></p>
<form method="POST" action="add.php">
<!--<input type="text" name="new_fname" class="Form-Control" placeholder="First Name" id="fname" required>-->
<input type="text" name="new_fname" class="Form-Control" placeholder="First Name" id="fname" required>
<input type="text" name="new_mname" class="Form-Control" placeholder="Middle Initial" id="mname" required>
<input type="text" name="new_lname" class="Form-Control" placeholder="Last Name" id="lname" required><br><br>
Select Your gender
<select name="new_gender">
<option value=""></option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
Select Your Status
<select name="new_status">
<option value=""></option>
<option value="New">New</option>
<option value="Old">Old</option>
<option value="Transferee">Transferee</option>
<option value="Shiftee">Shiftee</option>
</select>
Select Your Course
<select name="new_course">
<option value=""></option>
<option value="BSINFOTECH">BSINFOTECH</option>
<option value="BSIS">BSIS</option>
<option value="BSCOMTECH">BSCOMTECH</option>
</select>
<br><br>
<input type="text" name="new_age" class="Form-Control" placeholder="Age" id="age" required><br><br>
<input type="text" name="new_bp" class="Form-Control" placeholder="Birth Place" id="bp" required><br><br>
<input type="text" name="new_add" class="Form-Control" placeholder="Address" id="add" required><br><br>
<input type="text" name="new_nat" class="Form-Control" placeholder="Nationality" id="nat" required><br><br>
<input type="text" name="new_rel" class="Form-Control" placeholder="Religion" id="rel" required><br><br>
<input type="text" name="new_tel" class="Form-Control" placeholder="Tel. No." id="tel" required><br><br>
<input type="text" name="new_cel" class="Form-Control" placeholder="Cel. No." id="cel" required><br><br>
<input type="text" name="new_mail" class="Form-Control" placeholder="E-mail Address" id="mail" required><br><br>
<button onclick="parent.location='req.php'" type="submit" name="next">Next</button>
<button type="submit" class="btn" name="save" value="save">Save</button>
</form>
</body>
</html>
here is the req.php code:
<html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js">
</script>
<title>
REQUIRMENTS FORM
</title>
<br>
<p align="center" style="font-size: 50">REQUIRMENTS FORM</p>
</head>
<body>
<center>
<br>
<p align="center" style="font-size: 30">Registrar</p>
<form style="font-size: 20" action="add.php" method='post'>
Form 138
<br>
<select name="form1">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
Form 137A
<br>
<select name="form2">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
2 X 2 ID
<br>
<select name="picture">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
NSO Birth Certificate
<br>
<select name="nso">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
Good Moral Certificate
<br>
<select name="gmc">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<p align="center" style="font-size: 30">Library</p>
Library Card
<br>
<select name="lc">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
<br>
<p align="center" style="font-size: 30">Cashier</p>
<p><h4>You should have paid minimum of P2000.00-2500.00</h4></p>
<input type="text" name="cashier" class="Form-Control" width="100px" placeholder="Enter amount" id="cashier" required></input>
<button type="submit" style="font-size: 20" class="btn btn-primary btn-block" name="submit" value="save">SUBMIT</button>
<button type="button" style="font-size: 20" class="btn btn-primary btn-block"><a href="newform.php?id=<?php echo $data->new_id ?>">Process Student Copy</button>
<input type="hidden" value="<?php echo $data->new_id ?>" name="id" >
</form>
</body>
</html>
here is the add.php code:
<?php
mysql_connect("localhost","root");
mysql_select_db("enrollee");
$course=$_POST['new_course'];
$gender=$_POST['new_gender'];
$gender=$_POST['new_gender'];
$status=$_POST['new_status'];
$fname=$_POST['new_fname'];
$mname=$_POST['new_mname'];
$lname=$_POST['new_lname'];
$age=$_POST['new_age'];
$bp=$_POST['new_bp'];
$add=$_POST['new_add'];
$nat=$_POST['new_nat'];
$rel=$_POST['new_rel'];
$tel=$_POST['new_tel'];
$cel=$_POST['new_cel'];
$mail=$_POST['new_mail'];
form1=$_POST['form1'];
$form2=$_POST['form2'];
$picture=$_POST['picture'];
$nso=$_POST['nso'];
$gmc=$_POST['gmc'];
$lc=$_POST['lc'];
$cashier=$_POST['cashier'];
mysql_query("INSERT INTO new(new_id,new_course,new_gender,new_status,new_fname,new_mname,new_lname,new_age,new_bp,new_add,new_nat,new_rel,new_tel,new_cel,new_mail,form1,form2,picture,nso,gmc,lc,cashier))
VALUES(NULL, '$course','$gender', '$status', '$fname','$mname','$lname','$age','$bp','$add','$nat','$rel','$tel','$cel','$mail','$form1','$form2','$picture','$nso','$gmc','$lc','$cashier')");
header("Location: read.php");
?>
When you save the data into the database, you probably have one field that is primary key and auto increment, right? (if not, you should - label it ID or registration_id or some such)
On the req.php page, you should begin by reading the database - something like:
$result = mysql_query("SELECT * FROM new");
That will give you a MySQL resource containing all the fields in all the rows. You must then get each row, something like this:
while ($row = mysql_fetch_array($result){
echo $row['first_name'];
}
Use the above methodology to build your req.php page, containing the data you stored from registration.php page.
It may be helpful to you to do the Registration and Login tutorial over at codecourse.com, or to do a number of the PHP tutorials over at thenewboston
It might help you to know that you can get the ID of the last inserted row.
You can then use that ID to UPDATE (instead of INSERT) the data from the req.php file.
UPDATE `new` SET `fieldname` = '$value', `nuthername` = '$nextval' WHERE `new_id` = '$last_inserted_id'
I have a system which has only two transaction, Registration.php and req.php. The two transaction data are saved in the table new in my database. Registration.php is my first transacton, then req.php. This php files are form, which both has a submit button linked to add.php. The fields of my new table are devided in the two forms. The flow is that first Registration.php will be executed then req.php. My table new has a primary key named new_id and its auto increment. My problem is that, after execution of both forms, ONLY the data of Registration.php are save in the database table new and the req.php are blank. What is the problem? I need your help.
here is the Registration.php code:
<html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js">
</script>
<TITLE>
New Registration Form
</TITLE></head>
<body>
<center>
<br>
<p style="font-weight: bold; font-size: 30">Please Fill Out Your Information Sheet</p><p><?php
echo date('F j, Y, g:i a', time()+25200);
?></p>
<form method="POST" action="add.php">
<!--<input type="text" name="new_fname" class="Form-Control" placeholder="First Name" id="fname" required>-->
<input type="text" name="new_fname" class="Form-Control" placeholder="First Name" id="fname" required>
<input type="text" name="new_mname" class="Form-Control" placeholder="Middle Initial" id="mname" required>
<input type="text" name="new_lname" class="Form-Control" placeholder="Last Name" id="lname" required><br><br>
Select Your gender
<select name="new_gender">
<option value=""></option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
Select Your Status
<select name="new_status">
<option value=""></option>
<option value="New">New</option>
<option value="Old">Old</option>
<option value="Transferee">Transferee</option>
<option value="Shiftee">Shiftee</option>
</select>
Select Your Course
<select name="new_course">
<option value=""></option>
<option value="BSINFOTECH">BSINFOTECH</option>
<option value="BSIS">BSIS</option>
<option value="BSCOMTECH">BSCOMTECH</option>
</select>
<br><br>
<input type="text" name="new_age" class="Form-Control" placeholder="Age" id="age" required><br><br>
<input type="text" name="new_bp" class="Form-Control" placeholder="Birth Place" id="bp" required><br><br>
<input type="text" name="new_add" class="Form-Control" placeholder="Address" id="add" required><br><br>
<input type="text" name="new_nat" class="Form-Control" placeholder="Nationality" id="nat" required><br><br>
<input type="text" name="new_rel" class="Form-Control" placeholder="Religion" id="rel" required><br><br>
<input type="text" name="new_tel" class="Form-Control" placeholder="Tel. No." id="tel" required><br><br>
<input type="text" name="new_cel" class="Form-Control" placeholder="Cel. No." id="cel" required><br><br>
<input type="text" name="new_mail" class="Form-Control" placeholder="E-mail Address" id="mail" required><br><br>
<button onclick="parent.location='req.php'" type="submit" name="next">Next</button>
<button type="submit" class="btn" name="save" value="save">Save</button>
</form>
</body>
</html>
here is the req.php code:
<html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js">
</script>
<title>
REQUIRMENTS FORM
</title>
<br>
<p align="center" style="font-size: 50">REQUIRMENTS FORM</p>
</head>
<body>
<center>
<br>
<p align="center" style="font-size: 30">Registrar</p>
<form style="font-size: 20" action="add.php" method='post'>
Form 138
<br>
<select name="form1">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
Form 137A
<br>
<select name="form2">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
2 X 2 ID
<br>
<select name="picture">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
NSO Birth Certificate
<br>
<select name="nso">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
Good Moral Certificate
<br>
<select name="gmc">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<p align="center" style="font-size: 30">Library</p>
Library Card
<br>
<select name="lc">
<option value=""</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
<br>
<p align="center" style="font-size: 30">Cashier</p>
<p><h4>You should have paid minimum of P2000.00-2500.00</h4></p>
<input type="text" name="cashier" class="Form-Control" width="100px" placeholder="Enter amount" id="cashier" required></input>
<button type="submit" style="font-size: 20" class="btn btn-primary btn-block" name="submit" value="save">SUBMIT</button>
<button type="button" style="font-size: 20" class="btn btn-primary btn-block"><a href="newform.php?id=<?php echo $data->new_id ?>">Process Student Copy</button>
<input type="hidden" value="<?php echo $data->new_id ?>" name="id" >
</form>
</body>
</html>
here is the add.php code:
<?php
mysql_connect("localhost","root");
mysql_select_db("enrollee");
$course=$_POST['new_course'];
$gender=$_POST['new_gender'];
$gender=$_POST['new_gender'];
$status=$_POST['new_status'];
$fname=$_POST['new_fname'];
$mname=$_POST['new_mname'];
$lname=$_POST['new_lname'];
$age=$_POST['new_age'];
$bp=$_POST['new_bp'];
$add=$_POST['new_add'];
$nat=$_POST['new_nat'];
$rel=$_POST['new_rel'];
$tel=$_POST['new_tel'];
$cel=$_POST['new_cel'];
$mail=$_POST['new_mail'];
form1=$_POST['form1'];
$form2=$_POST['form2'];
$picture=$_POST['picture'];
$nso=$_POST['nso'];
$gmc=$_POST['gmc'];
$lc=$_POST['lc'];
$cashier=$_POST['cashier'];
mysql_query("INSERT INTO new(new_id,new_course,new_gender,new_status,new_fname,new_mname,new_lname,new_age,new_bp,new_add,new_nat,new_rel,new_tel,new_cel,new_mail,form1,form2,picture,nso,gmc,lc,cashier))
VALUES(NULL, '$course','$gender', '$status', '$fname','$mname','$lname','$age','$bp','$add','$nat','$rel','$tel','$cel','$mail','$form1','$form2','$picture','$nso','$gmc','$lc','$cashier')");
header("Location: read.php");
?>
I'm currently creating a custom 'survey'-like form but since I'm new to php, I am not entirely sure how to submit the entries to a database (and make a fieldset required).
I currently have 3 fieldsets, lets call them who, when and what. Who is a simple select field so no problem. When however is a group of radios but two of those have text fields associated that need to be filled if the radio was selected. What is just a textarea.
I understand this much:
Form action is a php file (which contains database connection and
submission)
Form method is post
With the database, how do I submit this data? Especially the second fieldset.
Current Form:
<form action="heroes.php" method="post">
<fieldset>
<h2 class="req">Which Hero?</h2>
<span class="help">We need to know what hero says what line.</span>
<label><span class="title">Hero: </span>
<select>
<?php include 'files/hero-select.php'; ?>
</select>
</label>
</fieldset>
<fieldset id="when">
<h2 class="req">When?</h2>
<span class="help">When is it said? Who is it said to?</span>
<label>To Boss: <input name="when" type="radio" value="boss" /> <input type="text" placeholder="Boss Name" id="bname" size="10" /></label>
<label>To Hero: <input name="when" type="radio" value="hero" /> <input type="text" placeholder="Hero Name" id="hname" size="10" /></label>
<label>Low Health: <input name="when" type="radio" value="lowhp" /></label>
<label>Defeat: <input name="when" type="radio" value="defeat" /></label>
<label>Boss Defeat: <input name="when" type="radio" value="bossd" /></label>
<label>Mob Defeat: <input name="when" type="radio" value="mob" /></label>
<label>Emote: <input name="when" type="radio" value="emote" /></label>
<label>Item Pickup: <input name="when" type="radio" value="item" /></label>
</fieldset>
<fieldset>
<h2 class="req">Quote</h2>
<span class="help">What was said.</span>
<textarea id="quote"></textarea>
</fieldset>
<fieldset>
<input type="submit" value="Submit" /><input type="reset" value="Clear" />
</fieldset>
</form>
hero-select.php:
Black Panther
<option value="Black Widow">
Black Widow
</option>
<option value="Cable">
Cable
</option>
<option value="Captain America">
Captain America
</option>
<option value="Colossus">
Colossus
</option>
<option value="Cyclops">
Cyclops
</option>
<option value="Daredevil">
Daredevil
</option>
<option value="Deadpool">
Deadpool
</option>
<option value="Emma Frost">
Emma Frost
</option>
<option value="Gambit">
Gambit
</option>
<option value="Ghost Rider">
Ghost Rider
</option>
<option value="Hawkeye">
Hawkeye
</option>
<option value="Hulk">
Hulk
</option>
<option value="Human Torch">
Human Torch
</option>
<option value="Iron Man">
Iron Man
</option>
<option value="Jean Grey">
Jean Grey
</option>
<option value="Loki">
Loki
</option>
<option value="Luke Cage">
Luke Cage
</option>
<option value="Moon Knight">
Moon Knight
</option>
<option value="Ms Marvel">
Ms Marvel
</option>
<option value="Nightcrawler">
Nightcrawler
</option>
<option value="Punisher">
Punisher
</option>
<option value="Rocket Raccoon">
Rocket Raccoon
</option>
<option value="Scarlet Witch">
Scarlet Witch
</option>
<option value="Spider-Man">
Spider-Man
</option>
<option value="Squirrel Girl">
Squirrel Girl
</option>
<option value="Storm">
Storm
</option>
<option value="Thing">
Thing
</option>
<option value="Thor">
Thor
</option>
<option value="Wolverine">
Wolverine
</option>
I'm gonna do a short example, with different code (but it works the same).
<form method="POST" action="add.php">
Name: <input type="text" name="name">
Phone: <input type="text" name="phone">
</form>
method="POST" means that it Posts all the info to the action, the action is set to add.php so it posts all the info to add.php.
As you can see every input above has a different name="", what the name property does is:
It sends every value together with a name, this means that the phone input gets send as Phone = "123456" and the name value Name = "2324234".
The add.php code
<?php
if ($_SERVER['REQUEST_METHOD']) == 'POST') {
$name = $_POST['name'];
$phone = $_POST['phone'];
$sql = 'INSERT INTO user '.
'(name,phone) '.
'VALUES ( "$name", "$phone"NOW())';
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
}
First it check if the request is a post, if it is it turns the value's it get send into variables and then it inserts the values into the database.
You can use jQuery with the .post method:
https://api.jquery.com/jQuery.post/
$.post("submittodatabase.php", $( "#yourformid" ).serialize() );