Jump to content

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

Go to solution Solved by Ch0cu3r,

Recommended Posts


... html form ...

$.post("mail.php", $("#contact").serialize(), function(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


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 !?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.