0

Hi,

For some reason form submit is not working properly while I am using Ajax.

I want the result to be displayed on the same page. I am using Ajax for this, but when I submit the form, only text is being displayed rather than the actual value.

This is the sample code

//THE FORM
<div id="leftcoloumn">
    <form action="javascript:ajaxpage('files/search2.php', 'rightcolumn')" method="POST">
                            Email :<input type="text" name="email" value=""/>
                            <input type="submit" value="Submit">
    </form>

</div>

<div id="rightcolumn">
    <div style="clear: left; margin-bottom: 1em"></div>

</div>

//THE PHP FILE - search2.php
<?php

    $email = $_POST['email'];
    echo "The Email ID is :";
    echo $email;
?>

<html>
<body>
    <h1>Hello World</h1>
</body>
</html>

//Problem - search2.php only displays "The Email ID is :"
//It does not display the actual value entered in the text field i.e $email

When I have only search2.php in the form action field, then it displays $email buit on a separate page.
I want the result to appear on the same page i.e under

<div id="rightcolumn">
        <div style="clear: left; margin-bottom: 1em"></div>

    </div>
2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by dany12
0

Your first problem is in the html because you don't give a name of submit to the input submit
Secondly you don't check to see if submit is pressed

if(isset($_POST['submit'])){

$email=$_POST['email'];

echo $email;

/*Ok now to put this in a div method you can use css on the div and the div is created only if email is returned*/
echo '<div id="yourid">'.$email.'</div>';


}

else{

echo'Error email is empty';
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.