Forums

How to add manual contact form in a page? (7 posts)

  1. hobbahobba
    Member
    Posted 1 year ago #

    I want to have a page where a user can insert their contact form (name, address, city, zip, email etc.). Their info will be stored in MyPhpAdmin database in a table. Is it possible to do it within wordpress template? I have a template specifically called template-join-us.php for this.

    I inserted these codes in the template right after the if (have_post()) loop:

    <? if ( $_POST['email'] ) { ?>
    
    <center>Thank you. You will be receiving a confirmation e-mail shortly.</center>
    
    <? } else { ?>
    <form action="index.php?page_id=4" method="post"> --> this is the location of submission
        Name: <input type="text" name="name" /><br />
        Address: <input type="text" name="address" /><br />
        City: <input type="text" name="city" /><br />
        State: <input type="text" name="state" /><br />
        Zip: <input type="text" name="zip" /><br />
        Email: <input type="text" name="email" /><br />
        Phone: <input type="text" name="phone" /><br />
        <br />
        <input type="submit" name="submit" value="submit" />
        </form>
    <? } ?>
    
    <? if ( $_POST['email'] ) {
        include_once("db.php"); --> to call localhost database to insert the contact form data
    
    $query  = "INSERT INTO contact_form (<code>name</code>, <code>address</code>, <code>city</code>, <code>state</code>, <code>zip</code>, <code>email</code>, <code>phone</code>, <code>stamp</code>) VALUES ('".$_POST['name']."', '".$_POST['address']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['email']."', '".$_POST['phone']."', NOW() )";
    
    $result = mysql_query($queryb) or die("Query Error: ".mysql_error());
    
    $emailsend = strval($_POST['email']);
    
    Code below is to change sender's email address to string so that the confirmation email will also be sent to sender's email as seen below
    
    if ( $result ) { mail( 'myself@myself.com' , 'Insert Header Topic Here' , 'Insert Email Content Here', 'From: webmaster@myself.com' . "\r\n" .
    
        'Reply-To: webmaster@myself' . "\r\n" .
        'X-Mailer: PHP/' . phpversion());
    	}
    mysql_close($db);
    }
    ?>

    I tried this code then did a test submission, then the page just gives a blank result with warning: "Sorry, no posts matched your criteria."

    What's wrong? How to fix it?

  2. hotkee
    Member
    Posted 1 year ago #

    why not use one of the plugins you can find somewhere in the plugins section on wordpress.org

  3. hobbahobba
    Member
    Posted 1 year ago #

    There is a plugin to do this? Which one?

  4. hobbahobba
    Member
    Posted 1 year ago #

    Nevermind

  5. idcoder
    Member
    Posted 11 months ago #

    hey did you ever find a solution for this..i have a exact similar problem.
    thanks

  6. Shane G
    Member
    Posted 11 months ago #

    Hello,

    You can use CForms plugin through which you can generate contact pages and add it into your blog..for details you can get it from below mentioned URL:

    http://wordpress.org/support/topic/224030?replies=16
    http://wordpress.org/extend/plugins/cforms/

    Thanks,

    Shane G.

  7. spstieng
    Member
    Posted 6 months ago #

    What if we need to store the form data in our own tables?
    Can we still use e.g. CForms?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.