No logro pasar variable formulario por json pero otras si se propagan, ayuda por favor
Publicado por morpheux (1 intervención) el 19/05/2017 09:46:00
Buenas, muchas gracias antes de nada, no logro enviar por json un variable nombre a un script php por post para que la inserte en la base de datos, pero la otra variable del formulario si se propaga, no veo ya donde puedo estar haciendo las cosas mal.
Logro que se propague el id y el email pero el nombre nada.
El formulario es este.
La función de json es esta
Y por último el script que lo gestiona y que no recoge el nombre es este
No sé que puede ser, porque el problema está entre el json y el php que recoge por post los datos, no recibe el dato, aunque en lugar de la variable le ponga un texto fijo, no llega al php.
Muchas gracias.
Logro que se propague el id y el email pero el nombre nada.
El formulario es este.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<div class="text-center" v-show="email_locker">
<p class="text-center"><?php _e('Enter your email to download this file!', 'onyxfiles'); ?></p>
<div v-show="show_alert" class="alert {{ alert_class }}">{{ alert_message }}</div>
<form id="jkof_emailDLForm" novalidate v-on:submit.prevent="submit_email">
<div class="form-group">
<label><?php _e('Enter E-mail', 'onyxfiles'); ?></label>
<input type="email" id="jkof_inputEmail" class="form-control" name="jkof_email" style="width:100%;">
<label>Nombre</label>
<input type="text" id="jkof_inputName" class="form-control" name="jkof_name" style="width:100%;">
</div>
<div class="form-group">
<button type="submit" class="rcw-purple rcw-medium rcw-button-7 btn-block">
<span class="icon-bg"></span><span class="button-icon fa fa-envelope"></span> <?php _e('Submit & Download File', 'onyxfiles'); ?>
</button>
</div>
</form>
<button type="button" class="rcw-silver rcw-small rcw-button-7 btn-block" v-on:click="go_back('email_locker')">
<span class="icon-bg"></span><span class="button-icon fa fa-arrow-left"></span> <?php _e('Go Back', 'onyxfiles'); ?>
</button>
</div>
La función de json es esta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
submit_email: function(){
this.show_alert = true;
this.alert_class = 'alert-info';
this.alert_message = jkof_dl_i18n.wait + ' ' + jkof_dl_i18n.adding_email;
var formObj = {
action: 'jkof_check_email',
fid: this.file_id,
jkof_email: $("#jkof_inputEmail").val(),
jkof_name: $("#jkof_inputName").val()
};
$.post( jkof_ajax_url, formObj, function(data){
if(data.status == 2){ // Instant
app.alert_class = 'alert-success';
app.alert_message = jkof_dl_i18n.success + ' ' + jkof_dl_i18n.getting_download;
app.check_download(app.file_id);
}else if(data.status == 3){
app.alert_class = 'alert-success';
app.alert_message = jkof_dl_i18n.success + ' ' + jkof_dl_i18n.emailing_download;
}else{
app.alert_class = 'alert-danger';
app.alert_message = jkof_dl_i18n.denied;
}
});
}
Y por último el script que lo gestiona y que no recoge el nombre es este
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function jkof_check_email(){
global $wpdb;
$output = array('status' => 1);
$email = secure($_POST['jkof_email']);
$nomb = $_POST['jkof_name'];
$fid = intval($_POST['fid']);
$file_settings = get_post_meta( $fid, 'jkof_dl_settings', true );
$jkof_settings = get_option( 'jkof_settings' );
$fields = array();
if(empty($file_settings) || !filter_var($email, FILTER_VALIDATE_EMAIL)){
$output['swag']=$email;
wp_send_json($output);
}
/*if(empty($nomb)) {
wp_send_json($output);
}*/
$domain_email = array_pop(explode('@', $email));
if(in_array($domain_email, $jkof_settings['blocked']['domains']) || in_array($email, $jkof_settings['blocked']['emails'])){
wp_send_json($output);
}
foreach( $_POST as $fk => $fv ){
if($fk == 'jkof_email'){
array_push($fields, array(
'email' => $email,
'name' => $nomb
));
continue;
}
}
$wpdb->insert(
$wpdb->prefix . 'of_emails',
array(
'form_fields' => json_encode($fields),
'fid' => $fid,
"time_sent" => time()
),
array( '%s', '%d', '%d' )
);
Muchas gracias.
Valora esta pregunta


0