Jump to content

Form doesn't send any data if form-file is loaded into index.php


bonaca

Recommended Posts

contact.php

... html form ...

$('#submit').click(function(){
$.post("mail.php", $("#contact").serialize(), function(response) {
$('#success').html(response);
});
return false;
}); 

mail.php is a separate file (for sending mail), and everything works in this arrangement.

 

But I need to load contact.php into index.php

$('#divR').load('chapters/contact.php'); 

so corresponding js line becomes

$.post("chapters/mail.php", $("#contact").serialize(), function(response) {... 

Submitting the form in this case response from mail.php is received, but POST array is empty, i.e. form doesn't send any data to mail.php !?

Can not use php to include contact.php?

<?php include 'chapters/contact.php'; ?>

Using PHP include will return the raw php source code of contact.php. The PHP code in contact.php will be parsed at the same time as index.php.

 

If you use jquery $.load() function it'll only return the html source code of contact.php (the output).

Does contact.php contain PHP code? .load() will only return the output from this script, no PHP source code is returned.

 

For example if contact.php had in it

$myVar = 'abc';

And then in index.php you had 

echo $myVar; 

the variable $myVar will be undefined. PHP code will not be passed back to index.php

 

If contact.php contains no PHP code then you are fine to use .load.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.