Saturday, 15 August 2015

ajax - Submitting hidden input values with jquery $.post empty db columns and Notice: Undefined index -



ajax - Submitting hidden input values with jquery $.post empty db columns and Notice: Undefined index -

i can see values passed in console nil in db , output undefined errors. d'ont think error in js, think error in how php file grabs info .post

here 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 form $('#data_form').submit(function(event) { alert('form submited'); // form info 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 form $.post('<?php echo $csamurl ; ?>', function(formdata) { // place success code here $("#feedback").html(formdata); alert(csactvskuip) }) .fail(function(data) { alert('this didnt work') }); // stop form submitting normal way , refreshing 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 wordpress plugin working on, have tested post using

if (isset($_post['submit'])) {

the values of form beingness set click function , works also, thing not having luck this.

you can pass form itselt. seek it.

$.post( "test.php", $( "#testform" ).serialize() );

jquery ajax post

No comments:

Post a Comment