Hi,

I have a contact form which is laid out like the following;

<form id="form1" name="form1" method="post" action="send.php">
    <table width="362" border="0" align="center" class="tbltxt">
    <tr>
    <td height="30" colspan="2" style="color:#174AA8; text-decoration:underline;"><b>Send us a message!</b></td>
    </tr>
    <tr>
    <td width="95" height="30"><label for="Name">Name</label></td>
    <td width="257"height="30"><input name="Name" type="text" id="Name" style="width:200px;" /></td>
    </tr>
    <tr>
    <td height="30"><label for="Subject">Subject</label></td>
    <td height="30"><select name="Subject" id="Subject" style="width:200px;">
    <option value="Technical issue">Technical issue</option>
    <option value="Rates">Rates</option>
    <option value="Other">Other</option>
    </select></td>
    </tr>
    <tr>
    <td height="30">Email address</td>
    <td height="30"><input name="Email" type="text" id="Email" style="width:200px;" /></td>
    </tr>
    <tr>
    <td valign="top">Message</td>
    <td><label for="Message"></label>
    <textarea name="Message" id="Message" rows="5" style="width:200px;"></textarea></td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td height="30"><input type="submit" name="send" id="send" value="Send now" />
    <input type="reset" name="Reset" id="button" value="Clear form" /></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </form>

After the user presses the 'Send now' button instead of it redirecting off to another page I want some text to appear below the table stating that the message has been sent.


Any ideas how I can achieve this?

Thanks :)

Recommended Answers

All 2 Replies

Change line 29 so that this button doesn't submit the page. Use the ONCLICK method to call the required javascript to send the data and display a message to the user. The form can then be reset or another page loaded from within the same script.

At the end of the send.php script try this code

echo "Message Sent";
sleep(2) 
header( 'Location: http://www.yoursite.com/' ) ;

This should put the message on screen saying mail sent, then wait two seconds before sending visitor back to main index page.

To get that mail sent message appear on the page where the contact form is takes a little variation and a bit more code.

header( 'Location: http://www.yoursite.com/contactform.php?text=message sent' ) ;

Same redirect as before but with the additional variable 'text' being passed. Then on the contact form page insert this where the message is to appear.

<div id=whatever>
<?php
$text = ($_POST["text"]);
echo $text ;
?>
</div>

It's quick and dirty but should work or at least give you some idea how to code exactly what you require.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.