从php对话框提交外部表单

I'm loading an external php page into a dialog on my user page (user.php). The external page (contact.php) contains a form.

I'd like to submit the form and then return a message to the user in the dialog.

When I run contact.php the form submits. I can't submit it from the dialog on user.php- I appreciate the help.

Here is the jquery from user.php

$(document).on('click', '#contact_tutor', function(){
$('div#dialog').load("contact.php?id="+uid)
.dialog({
    width: 800,
    height: 425,
    title: "Contact,
});
});

In the html on the first page (user.php)

<div id="contact_tutor" class="contact"><a href="#">Contact <?php echo $name;?></a></div>
<div id="dialog" ></div>

Here is the code from Contact.php

<?php
include_once($_SERVER['DOCUMENT_ROOT']."/MySite/php_includes/check_login_status.php");

if (isset($_POST['posted'])&& isset($_POST['message'])){
//do stuff
?>

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="style/style.css">

</head>

<body>
    <form id="message" method="POST" action="<?php echo $PHP_SELF;?>" class="contact">
    <label>Your Name:</label> <input type="text" name="sender_name" value=""></br>
    <label>Email:</label><input type="text" name="sender_email" value=""></br>
    <label>Message:</label><textarea class="textbox" cols="53" rows="10" name="message" value=""></textarea>
    <input type="hidden" name="posted" value="posted">
    <input type="Submit" value="Send Message">
    </form>
        <div class="statuserror"><?php echo $err?></div>
</body>
</html>

Just realised the problem - I'm using a php echo to define the form's action - which doesn't work and shows up null, replaced it with the hard coded string and everything is peachy!