I can see the values passed in the console but get nothing in the db and output is undefined errors. I d'ont think that the error is in my JS, I think the error is in how the PHP file grabs the data from .post
Here is my code:
Form:
<form id="data_form" action="" method="post">
<input id="csActvSkuIp" name="csActvSkuIp" type="hidden" value="" />
<input id="csActvSkuDtlsIp" name="csActvSkuDtlsIp" type="hidden" value="" />
<input id="csActvSkuCasePickIp" name="csActvSkuCasePickIp" type="hidden" value="" />
<input id="csActvSkuCasePickDtlsIp" name="csActvSkuCasePickDtlsIp" type="hidden" value="" />
<input id="csInputPicksPerMonthIp" name="csInputPicksPerMonthIp" type="hidden" value="" />
<input id="csInputPickRateIp" name="csInputPickRateIp" type="hidden" value="" />
<input id="csInputPickWrkr1Ip" name="csInputPickWrkr1Ip" type="hidden" value="" />
<input id="csInputPickWrkr2Ip" name="csInputPickWrkr2Ip" type="hidden" value="" />
<input id="csInputPickWrkr3Ip" name="csInputPickWrkr3Ip" type="hidden" value="" />
<input id="csInputPrcntPckingIp" name="csInputPrcntPckingIp" type="hidden" value="" />
<input id="csInputPickCostIp" name="csInputPickCostIp" type="hidden" value="" />
<input id="csCurrentPcpmIp" name="csCurrentPcpmIp" type="hidden" value="" />
<input id="csSubscriptionPerMonthIp" name="csSubscriptionPerMonthIp" type="hidden" value="" />
<input id="csPrcPerPickIp" name="csPrcPerPickIp" type="hidden" value="" />
<input id="csCartOnlySaveIp" name="csCartOnlySaveIp" type="hidden" value="" />
<input id="csSubPerMnLightsIp" name="csSubPerMnLightsIp" type="hidden" value="" />
<input id="csPrcPerPickLightsIp" name="csPrcPerPickLightsIp" type="hidden" value="" />
<input id="csCartOnlySaveLightsIp" name="csCartOnlySaveLightsIp" type="hidden" value="" />
<input type="submit" id="submit" name="submit" class="btn btn-info" />
</form>
jQuery:
<script type="text/javascript">
$( document ).ready(function() {
// process the form
$('#data_form').submit(function(event) {
alert('form submited');
// get the form data
var formData = {
csActvSkuIp : $( "input[name=csActvSkuIp]" ).val(),
csActvSkuDtlsIp : $( "input[name=csActvSkuDtlsIp]" ).val(),
csActvSkuCasePickIp : $( "input[name=csActvSkuCasePickIp]" ).val(),
csActvSkuCasePickDtlsIp : $( "input[name=csActvSkuCasePickDtlsIp]" ).val(),
csInputPicksPerMonthIp : $( "input[name=csInputPicksPerMonthIp]" ).val(),
csInputPickRateIp : $( "input[name=csInputPickRateIp]" ).val(),
csInputPickWrkr1Ip : $( "input[name=csInputPickWrkr1Ip]" ).val(),
csInputPickWrkr2Ip : $( "input[name=csInputPickWrkr2Ip]" ).val(),
csInputPickWrkr3Ip : $( "input[name=csInputPickWrkr3Ip]" ).val(),
csInputPrcntPckingIp : $( "input[name=csInputPrcntPckingIp]" ).val(),
csInputPickCostIp : $( "input[name=csInputPickCostIp]" ).val(),
csCurrentPcpmIp : $( "input[name=csCurrentPcpmIp]" ).val(),
csSubscriptionPerMonthIp : $( "input[name=csSubscriptionPerMonthIp]" ).val(),
csPrcPerPickIp : $( "input[name=csPrcPerPickIp]" ).val(),
csCartOnlySaveIp : $( "input[name=csCartOnlySaveIp]" ).val(),
csSubPerMnLightsIp : $( "input[name=csSubPerMnLightsIp]" ).val(),
csPrcPerPickLightsIp : $( "input[name=csPrcPerPickLightsIp]" ).val(),
csCartOnlySaveLightsIp : $( "input[name=csCartOnlySaveLightsIp]" ).val(),
};
//alert(formData.activesku);
console.log( formData );
// process the form
$.post('<?php echo $csamurl ; ?>', function(formData) {
// place success code here
$("#feedback").html(formData);
alert(csActvSkuIp)
})
.fail(function(data) {
alert('this didnt work')
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
});
</script>
<div id="feedback"></div>
PHP:
$ascasedtlsd = $_POST["csActvSkuCasePickDtlsIp"];
$activeskud = $_POST["csActvSkuIp"];
$askudttlsd = $_POST["csActvSkuDtlsIp"];
$ascasepickd = $_POST["csActvSkuCasePickIp"];
$pickspermonthd = $_POST["csInputPicksPerMonthIp"];
$pickrated = $_POST["csInputPickRateIp"];
$pickwrkroned = $_POST["csInputPickWrkr1Ip"];
$pickwrkrtwod = $_POST["csInputPickWrkr2Ip"];
$pickwrkrthrd = $_POST["csInputPickWrkr3Ip"];
$prcntpickd = $_POST["csInputPrcntPckingIp"];
$pickcostd = $_POST["csInputPickCostIp"];
$currentpcpmd = $_POST["csCurrentPcpmIp"];
$subpmad = $_POST["csSubscriptionPerMonthIp"];
$pprmnthad = $_POST["csPrcPerPickIp"];
$cartonlyd = $_POST["csCartOnlySaveIp"];
$subpmbd = $_POST["csSubPerMnLightsIp"];
$ppmnthbd = $_POST["csPrcPerPickLightsIp"];
$cartlightd = $_POST["csCartOnlySaveLightsIp"];
global $wpdb;
$table_name = $wpdb->prefix . 'codeshelf';
$wpdb->insert(
$table_name,
array(
'time' => current_time( 'mysql' ),
'activesku' => $activeskud,
'askudttls' => $askudttlsd,
'ascasepick' => $ascasepickd,
'ascasedtls' => $ascasedtlsd,
'pickspermonth' => $pickspermonthd,
'pickrate' => $pickrated,
'pickwrkrone' => $pickwrkroned,
'pickwrkrtwo' => $pickwrkrtwod,
'pickwrkrthr' => $pickwrkrthrd,
'prcntpick' => $prcntpickd,
'pickcost' => $pickcostd,
'currentpcpm' => $currentpcpmd,
'subpma' => $subpmad,
'pprmntha' => $pprmnthad,
'cartonly' => $cartonlyd,
'subpmb' => $subpmbd,
'ppmnthb' => $ppmnthbd,
'cartlight' => $cartlightd,
)
);
This is a WordPress plugin I am working on, but I have tested the post using
if (isset($_POST['submit'])) {
The values of the form are being set with a click function and this works also, the only thing that I am not having any luck with is this.