Form submits with a varied success PHP+IFRAME+AJAX
-
12-10-2022 - |
Question
I have a 3 steps checkout.
STEP: User upload a photo and crop it.
STEP: User add his shipping information.
STEP: User pay with PayPal.
Now, i want to save an information about the order in two steps.
I save the image information + upload image using iframe:
<form id="upload_form" enctype="multipart/form-data" method="post" action="<?php echo get_template_directory_uri(); ?>/upload.php" onsubmit="return checkForm()" target="image_upload_frame">
<iframe name="image_upload_frame" height="1" width="1" style="visibility: hidden"></iframe>
My upload.php upload the image to /cache/
directory and put data into database about link, framesize, and price, then it echo row_id
of the last row.
But it works sometimes and sometimes not! I mean I some time it do save information in DB and in some times no.
Any suggestions?
Here is another peace of code, where i call to .submit()
function
$(".steps a").click(function(){
$(".steps a").removeClass("selected");
$(this).addClass("selected");
});
$("#st1,#0stepnext").click(function(){
$('#upload_form').submit(function(){
$("#pagestep1").show();
$(".scrolldown").show();
$("#pagestep2").hide();
$("#pagestep3").hide();
});
});
$("#st2, #1stepnext").click(function(){
$("#pagestep2").show();
$("#pagestep1").hide();
$("#pagestep3").hide();
$(".scrolldown").hide();
});
$("#st3, #2stepnext").click(function(){
$("#pagestep3").show();
$("#pagestep1").hide();
$("#pagestep2").hide();
$(".scrolldown").hide();
});
Here is a part of my php:
$sImage = uploadImageFile();
global $wpdb;
$price = (int)$_POST['price'];
$frame = $_POST['filedim'];
$link = $sImage;
$id = $wpdb->insert_id;
$wpdb->insert('orders',
array(
'price'=>$price,
'frame'=>$frame,
'link'=>$link
),
array(
'%d',
'%s',
'%s'
)
);
echo $wpdb->insert_id;
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow