insert multiple rows to database - php

i have multiple rows insertion, so, i want to insert them into database.
i am trying to use loop function to send them to a table; but not success. Please anyone help with this?
//Adding New Line Item Function
var i = 1;
function AddNew(){
if (i <=3){ //if you don't want limit, you remove IF condition
i++;
var div= document.createElement('div');
div.innerHTML = '<input type="text" value="'+i+'" name="lineitem_'+i+'" maxlength="2" size="2"> <input type="text" name="materialcode_'+i+'" placeholder="Material Code" maxlength="18" size="18"> <input type="text" name="qty_'+i+'" placeholder="Quantity" maxlength="10" size="10"> <input type="text" name="price_'+i+'" placeholder="Price" maxlength="10" size="10"> <input type="button" onclick="removeItem(this)" value="-">';
document.getElementById('addingitem').appendChild(div);
}
}
function removeItem(div){
//document.getElementById('addingitem').removeChild(div.parentNode);
i--;
var addingitem = document.getElementById('addingitem');
addingitem.removeChild(div.parentNode);
var inputs = addingitem.querySelectorAll('[name^="lineitem_"]');
for (var r = 0; r < inputs.length; r++)
{
var item = inputs[r];
item.value = r + 1;
}
inputs = null;
}
//Validate Number Key
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode
return !(charCode > 31 && (charCode < 48 || charCode > 57));
}
<form method="post" action="make_order.php">
<!--Adding item-->
Item Detail:
<br />
<div id="addingitem">
<input type="text" name="lineitem_1" id="item" value="1" maxlength="2" size="2">
<input type="text" name="materialcode_1" placeholder="Material Code" maxlength="18" size="18">
<input type="text" name="qty_1" placeholder="Quantity" maxlength="10" size="10">
<input type="text" name="price_1" placeholder="Price" maxlength="10" size="10">
<input type="button" name="addnew" id="Add_New()" onClick="AddNew()" value="New Item">
</div>
<br />
<input type="submit" name="makeorder" value="Make Order">
</form>

Related

how to to automaticly get a multiple form

I'm doing a HTML form, it's meant to create step to pass on a game and I want to be able to enter a number and when for example I enter 5 it instantly show me 5 form to fill and create new step but when I try it doesn't appear how can I do please?
<h3>Insertion des étape :</h3>
<form action="InsertionEtape.php" method="post">
<input type="number" name="quantity" min="1" max="5">
<br>
<?php for ($i=0; $i < $_GET['quantity']; $i++) {
?>
<h5>Nom de l'étape</h5>
<input type="text" name="NomEtape" size="40" maxlength="40">
<br>
<h5> Description de l'étape </h5>
<textarea name="DescriptionEtape" rows="8" cols="80"></textarea>
<br>
<br>
<input type="submit" value="Valider">
<?php
} ?>
</form>
<h3>Insertion des étape :</h3>
<form action="index.php" method="post">
<input type="number" name="quantity" id="quantity" min="1" max="5">
<div id="formcontainer">
</div>
<input type="submit" value="Valider">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
jQuery(function($) {
$("#quantity").bind('keyup mouseup', function () {
var count = $('#quantity').val();
var htmlf = '';
for (i = 0; i < count; i++) {
htmlf += "<h5>Nom de l'étape</h5><br/>";
htmlf += '<input type="text" name="NomEtape_"'+i+' size="40" maxlength="40">';
htmlf += "<h5>Description de l'étape</h5><br/>";
htmlf += '<textarea name="DescriptionEtape_"'+i+' rows="8" cols="80"></textarea>';
htmlf += "<br/>"
}
$("#formcontainer").html(htmlf);
});
});
</script>
Simple Just run the code and you can find yourself easy.
Right so it sounds like you want this form to update on page. For this you'll need to use JavaScript. PHP runs server side only, you want this to update on the client side.
Here is a quick example to get you on the right path. I am using jQuery which is a popular Javascript library.
var $group = $('form .group').clone();
$('[name="quantity"]').on('change input keyup cut paste', function() {
var quantity = parseInt($(this).val());
$('form .group').remove();
for (var i = 0; i < quantity; i++) {
$group.clone().insertBefore('form [type="submit"]');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h3>Insertion des étape :</h3>
<form action="InsertionEtape.php" method="post">
<input type="number" name="quantity" value="1" min="1" max="5">
<br>
<div class="group">
<h5>Nom de l'étape</h5>
<input type="text" name="NomEtape[]" size="40" maxlength="40">
<br>
<h5> Description de l'étape </h5>
<textarea name="DescriptionEtape[]" rows="8" cols="80"></textarea>
<br>
</div>
<input type="submit" value="Valider">
</form>
okey I changed to this but an error appeared,
<form action="InsertionEtape.php" method="post">
<input type="number" name="quantity" min="1" max="5">
<br>
<?php for ($i=0; $i < $_GET['quantity']; $i++) {
echo "<h5>Nom de l'étape</h5>";
echo "<input type=\"text\" name=\"NomEtape_".$i."\" size=\"40\" maxlength=\"40\"> <br>";
?>
<h5> Description de l'étape </h5>
<textarea name="DescriptionEtape" rows="8" cols="80"></textarea>
<br>
<br>
<input type="submit" value="Valider">
<?php
} ?>
</form>
Notice: Undefined index: quantity in /***/**********/*****/******/WWW/Page_Administrateur/FormulaireInsertion.php on line 106

Show value while typing but only take first 6 number only, and change order of number

I have 2 fields when I type in ID NO field (first six number is date of birth with YYMMDDxxxxxx, (always contains 12 number), the DOB field will auto filled, based on ID NO, but the value of DOB only contains first 6 number in ID NO field and the order will be DDMMYY.
Example:
ID NO: 931121091010 (YYMMDD)
DOB : 211193 (DDMMYY)
var $dob = $("#dob");
$("#id_no").keyup(function() {
$dob.val(this.value);
});
$("#id_no").blur(function() {
$dob.val(this.value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<form>
<div>
<label>ID NO</label>
<input type="text" name="id_no" id="id_no" class="form-control" onKeyPress="return
goodchars(event,'1234567890',this)" required="" value="">
</div>
<div>
<label>DOB</label>
<input type="text" name="dob" id="dob" class="form-control" value="">
</div>
</form>
See the live example below:
var $dob = $("#dob");
$("#id_no").keyup(function() {
var str = this.value;
var strYYMMDD = str.substring(0, 6);
if (str.length > 6) {
var strDDMMYY = strYYMMDD.substring(4, 6) + strYYMMDD.substring(2, 4) + strYYMMDD.substring(0, 2);
$dob.val(strDDMMYY);
} else {
$dob.val("");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<div>
<label>ID NO</label>
<input type="text" name="id_no" id="id_no" class="form-control" maxlength="12" onKeyPress="return
goodchars(event,'1234567890',this)" required="" value="">
</div>
<div>
<label>DOB</label>
<input type="text" name="dob" id="dob" class="form-control" value="">
</div>
</form>

Form data to Json file as object

My json object should look like below, which is generating on submiting the form:
{
"range":{
"l1_price":
{"from":"0", "to":"260k", "price": "Rs .02"},
"l2_price":
{"from":"260k", "to":"500k", "price": "Rs .04"},
"l3_price":
{"from":"500k", "to":"1MM", "price": "Rs .007"},
"l4_price":
{"from":"1MM", "to":"2MM", "price": "Rs .003"}
}
}
Now the form is like:
<form class="json_out">
<p>
l1_price:
<input type="text" name="from_l1" placeholder="from range">
<input type="text" name="to_l1" placeholder="to range">
<input type="text" name="price_l1" placeholder="price">
</p>
<p>
l2_price:
<input type="text" name="from_l2" placeholder="from range">
<input type="text" name="to_l2" placeholder="to range">
<input type="text" name="price_l2" placeholder="price">
</p>
<p>
l3_price:
<input type="text" name="from_l3" placeholder="from range">
<input type="text" name="to_l3" placeholder="to range">
<input type="text" name="price_l3" placeholder="price">
</p>
<p>
l4_price:
<input type="text" name="from_l4" placeholder="from range">
<input type="text" name="to_l4" placeholder="to range">
<input type="text" name="price_l4" placeholder="price">
</p>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</p>
</form>
Finally i want to send the data to data.json file on submitting the form.
JavaScript code:
<script>
$('form.json_out').submit(function(e) {
var values = {};
var range = {};
var rates = [];
var thresholds = [];
var result = {};
e.preventDefault();
$.each($('form.json_out').serializeArray(), function(i, field) {
if(field.name){
temp = {};
name_split = field.name.split('_');
price_lev = name_split[1] + '_' + 'price';
val_str = name_split[0];
val = field.value;
temp[val_str] = val
if (val_str == 'price'){rates.push(val)};
if (val_str == 'to'){thresholds.push(val)};
if (range[price_lev]){
res = range[price_lev]
res[val_str] = val
range[price_lev] = res
}
else{
range[price_lev] = temp;
}
}
});
result['range'] = range
result['rates'] = rates
result['thresholds'] = thresholds
});
</script>

$_GET['email'] did not include the '#' character?

I made a custom form for forget password in WP.
below is the code that use:
<form name="lostpasswordform" id="lostpasswordform" action="'.wp_lostpassword_url().'" method="post">
<label for="user_login">Username:<br>
<input name="user_login" id="user_login" class="input" value="" size="" type="text"></label><br><br>
<label for="user_email">E-mail Address:<br>
<input name="user_email" id="user_email" class="input" value="" size="" type="text"></label>
<input type="hidden" name="" id="url_temp" value="'.str_replace( '%7E', '~', $_SERVER['REQUEST_URI']).'&axcelerate=forgotpassword">
<input name="redirect_to" value="&user_login=&user_email=" type="hidden" id="lostpasswordform_addon"><br><br>
<p class="submit">
<input name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Get New Password" type="submit">
</p>
</form>
<script>
jQuery('#lostpasswordform #user_login').blur(function() {
jQuery('#lostpasswordform_addon').val( jQuery('#url_temp').val() + '&user_login=' + jQuery(this).val() + '&user_email=' + jQuery('#lostpasswordform #user_email').val());
});
jQuery('#lostpasswordform #user_email').blur(function() {
jQuery('#lostpasswordform_addon').val( jQuery('#url_temp').val() + '&user_login=' + jQuery('#lostpasswordform #user_login').val() + '&user_email=' + jQuery(this).val());
});
</script>
I have a problem in the email value when I check into redirect_to the email format is correct eg. nameof#mail.com
but when I try to set up in a function suing this code:
if($_GET['axcelerate'] == 'forgotpassword'){
echo $_GET['user_email'];
}
it returns nameofmail.com and not nameof#mail.com ?
does anyone have an idea about my case?

Run function when pressing button and insert into form

So I have this form, where I want to add a button which makes a function run.
This is how my form looks like:
<form action="" method="POST">
CVR-nummer:<br>
<input name="cvr" id="cvr" type="text" value="" size="30"/> <button onclick="<?php getinfo(); ?>">Run the function</button><br>
Navn:<br>
<input name="navn" type="text" value="<?php if(isset($navn)) {echo $navn;} ?>" size="30"/><br>
Adresse:<br>
<input name="adresse" type="text" value="<?php if(isset($adresse)) {echo $adresse;} ?>" size="30"/><br>
Postnummer:<br>
<input name="postnr" type="text" value="<?php if(isset($postnr)) {echo $postnr;} ?>" size="30"/><br>
By:<br>
<input name="by" type="text" value="<?php if(isset($by)) {echo $by;} ?>" size="30"/><br>
<input type="submit" value="Registrer"/>
</form>
And this is my function which uses an API
<?php
function getinfo() {
$cvr = "12345678";
$api = json_decode(file_get_contents("http://cvrapi.dk/{$cvr}/"),true);
$navn = $api['navn'];
$adresse = $api['adresse'];
$postnr = $api['postnr'];
$by = $api['by'];
}
?>
When I click the button I want it to:
1. Get value of the cvr-field.
2. Validate cvr-field so it has exactly 8 numbers.
3. If validation OK it must set the variables.
4. The variables must be shown in the form.
Any thoughts on how to do this?
UPDATE
<script type="text/javascript">
function checkCVR()
{
var cvr = document.getElementById("cvr").value;
var reg = new RegExp("^[0-9]{8}$");
if(!reg.test(cvr))
{
document.getElementById("cvr_error").style.display = 'block';
document.getElementById("cvr_error").innerHTML = "CVR Error!";
}
else
{
document.getElementById("cvr_error").style.display = 'none';
// var url = "http://cvrapi.dk/"+cvr+"/";
// var url = "http://haxify.org/result.php";
var url = "json.txt";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var json = JSON.parse(xmlhttp.responseText);
document.getElementById("navn").value = json["navn"];
document.getElementById("adresse").value = json["adresse"];
document.getElementById("postnr").value = json["postnr"];
document.getElementById("by").value = json["by"];
}
};
xmlhttp.send(null);
}
}
</script>
<form action="" method="POST">
CVR-nummer:<br>
<input name="cvr" id="cvr" type="text" value="" size="30"/>
<input type="button" onClick="checkCVR()" value="Run the function" /><br />
<span id="cvr_error" style="color:red;display:none;"></span>
Navn:<br />
<input name="navn" id="navn" type="text" value="" size="30"/><br />
Adresse:<br />
<input name="adresse" id="adresse" type="text" value="" size="30"/><br />
Postnummer:<br />
<input name="postnr" id="postnr" type="text" value="" size="30"/><br />
By:<br />
<input name="by" id="by" type="text" value="" size="30"/><br />
<input type="submit" value="Registrer"/>
</form>
This one actually works on one website but does not work on my own site. Is there any requirements for any software or something, or what can be the reaseon for this to not work on my specific website?
Test:
http://haxify.org/form_v4.php

Categories