I’m creating an order form for a client and would like it to be completely contained within the one page (ie no page reloading / refreshing on submit). I have the submit part working, but now I’m trying to get the submitted order to appear below the form. I’ve been pulling my hair out, trying whatever I can to get it to work.
I have a jquery .ajaxform request which properly submits the form, then another jquery .ajax request passing the entry_id to a page which should send back the new order.
Here’s my current code:
$(document).ready(function() {
$('#typecolour2').ajaxForm({
target: '#saved_orders',
dataType: 'json',
success: showResponse ,
});
});
function showResponse(responseText, statusText, xhr, $form) {
var rt = responseText;
var stringified = JSON.stringify(rt, undefined, 2);
var objectified = $.parseJSON(stringified);
var eid = objectified.entry_id;
$.ajax({
url:"requestOrders?id="+eid,
success:function(result){
$("#saved_orders").html(result);
}
});
}It works sending the entry_id, but my issue is on the other side - formulating the code to send back the new order. My biggest problem is that my order entry contains related entries, which are based on other related entries… (I’m trying to make the backend as flexible as possible).
The ajax will not accept a typical EE template with {exp:channel:entries} tags and such; it’s only accepting PHP. But my PHP query is SOOO bloated with the related entries, and it’s going a little above my head… I want as few queries as possible.
My current query:
<?
$oid = $_GET['id'];
$query2 = $this->EE->db->query("
SELECT d.field_id_15 AS order_quantity,
d.field_id_19 AS order_photo,
d.field_id_20 AS order_print_option,
d1.entry_id AS photo_id,
d1.field_id_27 AS photo_proof_number,
d1.field_id_10 AS photo_link,
d1.field_id_18 AS photo_session,
d2.entry_id AS session_id,
d2.field_id_16 AS session_name,
d3.entry_id AS print_option_id,
d3.field_id_11 AS print_option_type,
d3.field_id_12 AS print_option_style,
d4.entry_id AS type_id,
d4.field_id_22 AS type_name,
d4.field_id_23 AS type_image,
d5.entry_id AS colour_id,
d5.field_id_21 AS colour_name,
d5.field_id_24 AS colour_image
FROM exp_channel_data AS d
LEFT JOIN (exp_channel_data AS d1
LEFT JOIN exp_relationships AS r1
ON (r1.rel_parent_id = '$oid'
AND r1.rel_child_id = 'photo_id'))
ON r1.rel_id = 'order_photo'
LEFT JOIN (exp_channel_data AS d2
LEFT JOIN exp_relationships AS r2
ON (r2.rel_parent_id = '$oid'
AND r2.rel_child_id = 'session_id'))
ON r2.rel_id = 'photo_session'
LEFT JOIN (exp_channel_data AS d3
LEFT JOIN exp_relationships AS r3
ON (r3.rel_parent_id = '$oid'
AND r3.rel_child_id = 'print_option_id'))
ON r3.rel_id = 'order_print_option'
LEFT JOIN (exp_channel_data AS d4
LEFT JOIN exp_relationships AS r4
ON (r4.rel_parent_id = '$oid'
AND r4.rel_child_id = 'type_id'))
ON r4.rel_id = 'print_option_type'
LEFT JOIN (exp_channel_data AS d5
LEFT JOIN exp_relationships AS r5
ON (r5.rel_parent_id = '$oid'
AND r5.rel_child_id = 'colour_id'))
ON r5.rel_id = 'print_option_style'
WHERE d.entry_id = '$oid'
");
echo $query2->num_rows();
$results = $query2->result_array(0);
print_r($results);
?>This isn’t working… Any ideas / suggestions / obvious errors?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.