admin管理员组文章数量:1429027
When I make a modification to data that is read into a form using MYSQL, I want to apply those changes to the database. But even when successfully submitting a form, the $_POST
values are not changing, they remain with the old values.
I am seeing the changed value in AJAX, and I even try an insert into the database with the values in AJAX, but that is not working...
I have spent days on this, can anyone help? If I could get if(isset($_POST['FirstName']))
to fire off, then I would be good, but I can't seem to get this to happen. I will attach portions of my code, there is a lot, but I will attach the ones that are applicable.
// SNIPPETS FROM THE FORM: This is contained in php_DOC.php
<form id="PhysicianForm" method="POST" enctype="multipart/form-data"
autocomplete="off" action="<?php echo admin_url('admin-ajax.php'); ?>" >
<input type="hidden" name="action" value="CreateProfile">
// This prints out the modified FirstName value correctly, this is the only place I can get the modified value. This is contained in php_DOC.php
jQuery('#SubmitInsHrs').click( function () {
var FirstName = jQuery('#FirstName').val();
alert('FirstName being updated...', FirstName);
console.log(FirstName);
jQuery.ajax({
url: 'admin-ajax.php',
type: "POST",
data: {
'action': 'post_language',
'FirstNM': FirstName,
},
success: function (data) {
alert(data);
}
});
});
These are in functions.php
add_action('wp_enqueue_scripts','enqueue_jqery_form');
add_action('wp_ajax_CreateProfile','CreateProfile');
function CreateProfile(){
wp_send_json_success( $_POST );
}
function enqueue_jqery_form (){
wp_enqueue_script('jquery-form');
}
I also tried this, to just force insert with new value, but no insert happens….
function post_language(){
global $wpdb;
alert('post_language is called');
$FirstName = isset( $_POST['FirstName'] ) ? $_POST['FirstName'] : '';
$table = 'Provider';
$wpdb->insert( $table, array('FirstNM' => $FirstName));
}
add_action('wp_ajax_post_language', 'post_language');
When I make a modification to data that is read into a form using MYSQL, I want to apply those changes to the database. But even when successfully submitting a form, the $_POST
values are not changing, they remain with the old values.
I am seeing the changed value in AJAX, and I even try an insert into the database with the values in AJAX, but that is not working...
I have spent days on this, can anyone help? If I could get if(isset($_POST['FirstName']))
to fire off, then I would be good, but I can't seem to get this to happen. I will attach portions of my code, there is a lot, but I will attach the ones that are applicable.
// SNIPPETS FROM THE FORM: This is contained in php_DOC.php
<form id="PhysicianForm" method="POST" enctype="multipart/form-data"
autocomplete="off" action="<?php echo admin_url('admin-ajax.php'); ?>" >
<input type="hidden" name="action" value="CreateProfile">
// This prints out the modified FirstName value correctly, this is the only place I can get the modified value. This is contained in php_DOC.php
jQuery('#SubmitInsHrs').click( function () {
var FirstName = jQuery('#FirstName').val();
alert('FirstName being updated...', FirstName);
console.log(FirstName);
jQuery.ajax({
url: 'admin-ajax.php',
type: "POST",
data: {
'action': 'post_language',
'FirstNM': FirstName,
},
success: function (data) {
alert(data);
}
});
});
These are in functions.php
add_action('wp_enqueue_scripts','enqueue_jqery_form');
add_action('wp_ajax_CreateProfile','CreateProfile');
function CreateProfile(){
wp_send_json_success( $_POST );
}
function enqueue_jqery_form (){
wp_enqueue_script('jquery-form');
}
I also tried this, to just force insert with new value, but no insert happens….
function post_language(){
global $wpdb;
alert('post_language is called');
$FirstName = isset( $_POST['FirstName'] ) ? $_POST['FirstName'] : '';
$table = 'Provider';
$wpdb->insert( $table, array('FirstNM' => $FirstName));
}
add_action('wp_ajax_post_language', 'post_language');
Share
Improve this question
edited Apr 30, 2019 at 18:44
Qaisar Feroz
2,1471 gold badge9 silver badges20 bronze badges
asked Apr 30, 2019 at 17:23
MonicaMonica
1
2
|
1 Answer
Reset to default 1Add this to functions.php
add_action('wp_ajax_post_language','post_language');
and then make either of following changes in your code.
Because your jquery code is sending FirstNM
to server (not FirstName
).
Therefore in post_language()
function, change this line
$FirstName = isset( $_POST['FirstName'] ) ? $_POST['FirstName'] : '';
to
$FirstName = isset( $_POST['FirstNM'] ) ? $_POST['FirstNM'] : '';
OR
Change 'FirstNM': FirstName,
to 'FirstName': FirstName,
in ajax call.
data: {
'action': 'post_language',
'FirstName': FirstName, // 'FirstNM': FirstName,
}
UPDATE:
Also remove this line,from post_language()
function if yo have not defined alert()
in your PHP It seems to be a JS function added to PHP by mistake, resulting in a PHP error.
alert('post_language is called');
本文标签: phpA POST should occur when submit form but is not
版权声明:本文标题:php - A $_POST should occur when submit form but is not? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745531192a2662067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_ajax_nopriv_{action-name}
, in this casewp_ajax_nopriv_CreateProfile
. – nmr Commented May 2, 2019 at 20:40