We are working on a large form and there is 1 option for selecting installments for user, so we are using form select to show duration like 6 12 18 24 30 36 and it should give 6 boxes if admin selects 6 with 2 input fields DATE and Amount after that it should be saved to mysql using php, so can you give some advice or code please? thanks...
#seopps AFAIU you want a raw format, how to develope a form and proceed further, i m giving u just a hint, you can manipulate/modify according to your need
installment.php
<script type="text/javascript">
$(document).ready(function(){
$('select').change(function () {
$('div#wayofpay').show();
});
});
</script>
<form method="post" action="nextpage.php">
<select name="installment" id="installment">
<option value=''>Select Duration:</option>
<?php foreach(range(0,36,6) as $ts) { ?>
<option value='<?php echo $ts?>'><?php echo $ts;?></option>
<?php } ?>
</select>
<div id="wayofpay" style="display:none">
<label for='start_date'>Date:</label><input type="text" name="start_date" id="start_date" value="">
<label for='amount'>Amount:</label><input type="text" name="amount" id="amount" value="">
</div>
</form>
nextpage.php
$post_data = array_map('mysql_real_escape_string',$_POST);
// create mysql connection and use below query
$qry= "INSERT INTO yourtable SET
installment_duration = $post_data['installment'];
start_date=$post_data['start_date'];
amount =$post_data['amount'] ";
mysql_query($qry);
For the client side you can use the below jQuery script
Working example here
Enter Duration: <input type="text" id="duration" />
<button>Go</button><br />
<form id="orders">
</form>
And the javascript..
<script>
$('button').click(function(){
var count = parseInt($('#duration').val(), 10);
if(!isNaN(count)){
for(i=1;i<=count;i++){
$('#orders').append(i+". ").append("<input class='item' /><br />");
}
}
});
</script>
For the MySQL php part there are numerous examples available out there and a little googling will certainly help.
Related
in a php form I have the list of brands scrollable from a select field and I would modify the selected brand displaying it in a field beside.
The php form is this:
<?php
include '../sys/conn.php';
$brands = mysqli_query ($conn, "
*(query to select brands name and id)*
") or die ("Query not valid: " . mysqli_error($conn));
mysqli_close($conn);
?>
...
<form role="form" >
<label>Brands List</label>
<select class="form-control" name='brands list'>
<?php while ($listabrand=mysqli_fetch_array($brands)){
echo '<option>'.$listabrand['0'].' - '.$listabrand['1'].'</option>';
}?>
</select>
...
<label>Modify Brand</label>
<input type="text" name='brand-name' class="form-control" required placeholder="Brand Name to modify">
</form></html>
Basically I need to select the brand's name from the named "brands list" field and display it into the 'brand-name' in order to modify and save it.
Any help?
First of all, name attribute cannot contain space.
Correct this in <select class="form-control" name='brands list'>
And for the displaying selected brand in the value of text field, use javascript or jquery.
Showing example in JQuery:
$('select[name="brands-list"]').change(function(){
var selectedBrand = $(this).val();
$('input[name="brand-name"]').val(selectedBrand);
});
This is the right code.
<select class="form-control" name='brands-list'>
<?php
while ($listabrand=mysqli_fetch_array($brands)){
echo '<option value="'.$listabrand['1'].'">'.$listabrand['0'].' - '.$listabrand['1'].'</option>';
}?>
</select>
<div class="col-lg-8">
<form role="form">
<div class="form-group">
<label>Marca</label>
<input type="text" name='brand-name' class="form-control">
</div>
</form>
</div>
<script>
$('select[name="brands-list"]').change(function(){
var selectedBrand = $(this).val();
$('input[name="brand-name"]').val(selectedBrand);
});
</script>
I am working on a project called online Test, where users can take the test. I have created a php code in the following format but its hard coded. Below is the code. If I click on C it will take me to c test and similarly c++
<center><h2><b>Select the test</b></h2>
<div class="test"><b>C</b></div><br>
<div class="test"><b>C++</b></div><br>
</center>
Now the question is I want to make this page has dynamic. To fetch all the course that are there in the database and if user selects a particular test, he should get the test for that particular subject.
<form action="promo.php" method="post">
<h2><center>
<td><select name="links" id="links" value=' ' ">
<?php
while($row=mysql_fetch_array($out))
{
echo "<option value=" .$row['course_id']." > ". $row['c_name']." </option>";
}
?>
</select>
<input type="Submit" value="Start" /></center>
</form>
This is what I have done, it displays all the courses in the drop down fetching from the database. When I click the start button, it does not start any test because promo.php requires another parameter.
I am not able to send the course name along with the promo.php. How to do this
Can any one help me with this code
As some points is not cleared but I assume you can do like this :
Change select box name to name="course"
<select name="course" id="course">
And if you want to send a select box value to a page like this : promo.php?course=c then you should do method = "get" :
<form action="promo.php" method="get">
<h2><center>
<select name="course" id="course">
<?php
while($row=mysql_fetch_array($out))
{
echo '<option value="'.$row['c_name'].'" > '.$row['c_name'].' </option>';
}
?>
</select>
<input type="Submit" value="Start" /></center>
</form>
Perhaps I misunderstood the question, but why not include the other parameter in your form? Just add another <input type="text">, <select> or <input type="hidden">, as appropriate.
Got a simple form made of a text input and a option select input. When submititing, Firebug shows me that on POST no value from the option input has been sent, only the value from the text one. After checking other similar questions, don't find any spelling mistake...
FORM:
<form id="turn_conf" method="POST" action="config/forms/turn_conf/turn_insert.php">
<div class="smartFormContent">
<p class="inputForm">
<label for="nombre">Nombre:</label>
<input id="tu_name" class="" type="text" value="" name="tu_name">
</p>
<p class="inputForm">
<label for="tipo">Tipo turno:</label>
<select id="tu_type" class="" name="tu_type">
<option value="1">MaƱana</option>
<option value="2">Tarde</option>
<option value="3">Noche</option>
</select>
</p>
<input class="smartFormSubmit" type="submit" value="Crear" name="submit">
</div>
</form>
Firebug shows posted data as:
FIY: this POST form is sent by jQuery, here is the code:
function validaDatos(e)
{
var turnName = $('input[name=tu_name]').val();
var turnType = $('input[name=tu_type]').val();
$.post($(this).attr('action'), { tu_name:turnName, tu_type:turnType }).success(feedback);
var emptyRow='<div class="tableRow newRow"><div class="contentColumn60"><span class="tableContentText"></span></div><div class="contentColumn20"><span class="tableContentText"></span></div><div class="contentColumn10"><div class="tableIconLink"></div></div><div class="contentColumn10"><div class="tableIconLink"></div></div></div>';
$(emptyRow).prependTo('.tableContent').hide().slideDown(500);
messageInsert();
e.preventDefault();
}
function feedback (datos) {
var content= datos;
$('.newRow').html(datos);
}
There are duplicate FORM tags:
<form method="POST" action="config/forms/turn_conf/turn_insert.php" id="turn_conf">
<form id="turn_conf" method="POST" action="config/forms/turn_conf/turn_insert.php">
This will probably cause the browser not to post the data properly.
The two FORM tags also share the same ID which is not permitted id="turn_conf".
var turnType = $('input[name=tu_type]').val()
tu_type is not an input, is a select. This will work:
var turnType = $('select[name=tu_type]').val()
I have a select multiple list that has a few items in it. It is a list of IP addresses for an ACL. People can add/remove IPs, and then save the list. However, unless you select an item on the list, $_POST[selectName] does not contain any values. How can I accomplish this? I know I can do this with javascript but I would rather stick to PHP.
Edit/corrected: You need JS. There is no way to send all (selected and not selected) options via POST. You have to programatically select all options before submission.
File with form (file1.php):
<script type="text/javascript">
function selectAll()
{
selectBox = document.getElementById("someId");
for (var i = 0; i < selectBox.options.length; i++)
{
selectBox.options[i].selected = true;
}
}
</script>
<form method="post" action="file2.php">
<select id="someId" name="selectName[]" multiple>
<option value="123.123.123.123">123.123.123.123</option>
<option value="234.234.234.234">234.234.234.234</option>
</select>
<input type="submit" name="submit" value=Submit onclick="selectAll();">
</form>
File that receives POST (file2.php):
<?php
foreach ($_POST['selectName'] as $item)
{
print "$item<br/>";
}
?>
Just to tack on this you could also use the jQuery version of #Kamil's code which is a little simpler than the loop:
<script type="text/javascript">
jQuery('[name="form1"]').on("submit",selectAll);
function selectAll()
{
jQuery('[name="selectName[]"] option').prop('selected', true);
}
</script>
<form name="form1" method="post" action="file2.php">
<select id="someId" name="selectName[]" multiple>
<option value="123.123.123.123">123.123.123.123</option>
<option value="234.234.234.234">234.234.234.234</option>
</select>
<input type="submit" name="submit" value=Submit onclick="selectAll();">
</form>
Can anybody help me on this. For showing the rezults from an MySql database i have to select school, class, subject, and exam. But listing all the classes or all the exams is not very practical so i want to do another function that when i choose some schools in the first select box it shows me in the second select box only the classes of the selected schools.
My code is:
<div id="allselects">
<form action="viewing.php" method="post" name="filt">
<div class="multsarrange">
<h1 class="choosetext" >Chose Schools</h1>
<select class="multipleselect" name="schools[]" size="8" multiple="multiple" id="shkll">
<?php
$sql = "SELECT * FROM schools ";
$scc=mysql_query($sql);
while ($db_f = mysql_fetch_assoc($scc)) {
$schcd=$db_f['schoolcode'];
$schc=$db_f['schoolname'];
echo "<option value=$schcd >$schc</option>";
}
?>
</select>
</div>
<div class="multsarrange" id="clasaajax">
<h1 class="choosetext" >Chose an Classes</h1>
<select class="multipleselect" name="classes[]" size="8" multiple="multiple" ">
<?php
$c = "SELECT * FROM classes ";
$cl=mysql_query($c);
while ($db_f = mysql_fetch_assoc($cl)) {
$clsc=$db_f['schoolID'];
$claid=$db_f['classID'];
$clay=$db_f['year'];
$clanm=$db_f['className'];
$name=schoolidton($clsc)." ".$clay." ".$clanm;
echo "<option value=$claid >$name</option>";
}
?>
</select>
</div>
<div class="multsarrange">
<h1 class="choosetext" >Chose Subjects</h1>
<select class="multipleselect" name="subjects[]" size="8" multiple="multiple">
<?php
$sb = "SELECT * FROM subjects ";
$sbi=mysql_query($sb);
while ($db_f = mysql_fetch_assoc($sbi)) {
$sbnm=$db_f['subjectName'];
$sbid=$db_f['subjectID'];
echo "<option value=$sbid >$sbnm</option>";
}
?>
</select>
</div>
<div class="multsarrange">
<h1 class="choosetext" >Chose Exams</h1>
<select class="multipleselect" name="exams[]" size="8" multiple="multiple">
<?php
$e = "SELECT * FROM exams ";
$ex=mysql_query($e);
while ($db_f = mysql_fetch_assoc($ex)) {
$id=$db_f['examID'];
$sub=$db_f['subjectID'];
$desc=$db_f['description'];
$year=$db_f['year'];
$data=$db_f['data'];
$exnam=subidton($sub)." - ".$year." - ".$desc." - ".$data;
echo "<option value=$id >$exnam</option>";
}
?>
</select>
</div>
<div id="longsubmit">
</br></br>
<input name="submit" type="submit" value="View" />
</div>
</form>
</div>
What you need to do is the following :
Setup an event listener on the select to listen for the change event - see here
Process the change event by sending the selected value to the PHP script - see here
Using PHP get the selected value and query the database as required (you already do that bit)
Send the associated HTML output or JSON or XML if you just creating a new select list - this is a simple echo
Write the output to the screen using JavaScript - this is either creating a new element based on the reply from the PHP function or inserting the HTML response
There are lots of things within this process - each with multiple options - i suggest you attempt to tackle each one and come back with specific questions if you get stuck
use ajax on abc.php get values or ids of school and make the tags you need and return back the results to the relevant id of html
function get_options(table,id_field,name_field,where_field,field_value,select_id,edit_id){
$('#'+select_id).html('<option>Loading...</option>');
$.ajax({
type: "POST", url: "abc.php", data: "&table="+table+"&id_field="+id_field+"&name_field="+name_field+"&where_field="+where_field+"&field_value="+field_value+ "&edit_id=" + edit_id +"&get_option=1",
complete: function(data){
//alert(data.responseText);
$('#'+select_id).html(data.responseText);
}
});
}
You have to use AJAX inorder to achieve this.
check this
http://www.plus2net.com/php_tutorial/ajax_drop_down_list.php