?
Solved

wordpress contact form

Posted on 2011-10-20
20
Medium Priority
?
410 Views
Last Modified: 2012-05-12
Hi

I am trying to develop a contact form on a wordpress page, but I dont want to use any plugins, just my own php/html.

All I want to do it post the form contents back to the same page, so that I can process the form using php (which is in the same page as the form) and either display errors or redirect to a thank you page. simples...

or maybe not...

The page displays perfectly, but whenever I click 'send' it returns back to my blog page, but the url is for the contact page?? kind of weird thing going on there...

I have the following form declaration:

<form id='contactform' method='post' action=''>


0
Comment
Question by:cycledude
  • 12
  • 5
  • 3
20 Comments
 
LVL 6

Expert Comment

by:joeypolice
ID: 36999766
May I ask why you are not wanting to use any plugins?  This is a great one which can be customized easily.

http://wordpress.org/extend/plugins/contact-form-7/

-Joey
0
 

Author Comment

by:cycledude
ID: 36999912
Reason is I have my own script with jquery and php to handle the processing, which I like more...

I have used contact for 7, and dont really like it...
0
 
LVL 6

Expert Comment

by:joeypolice
ID: 36999966
You could try this: http://www.phpeasystep.com/phptu/8.html

Or, I have a simple PHP script that I have used several times which is easy to implement.  I would be happy to email it to you.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 36999976
just to clarify,

you have a contact form on a page like www.yourblog.com/contact

you submit the page to itself

after submit it displays www.yourblog.com/contact in the url but is showing the page from www.yourblog.com

0
 
LVL 6

Assisted Solution

by:joeypolice
joeypolice earned 800 total points
ID: 36999989
This is the PHP code:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'youremail@yahoo.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$cf_email."\r\n";
$headers .= 'Reply-To: '.$cf_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'contact_page.html';
	</script>
<?php
}
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to gordon@template-help.com');
		window.location = 'contact_page.html';
	</script>
<?php
}
?>

Open in new window

0
 

Author Comment

by:cycledude
ID: 36999992
@jrm213jrm213:

you got it mate, spot on


0
 
LVL 6

Expert Comment

by:joeypolice
ID: 37000002
This is the HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form</title>
</head>

<body>
<form action="contact.php" method="post">
	Your name<br>
    <input type="text" name="cf_name"><br>
	Your e-mail<br>
    <input type="text" name="cf_email"><br>
	Message<br>
    <textarea name="cf_message"></textarea><br>
	<input type="submit" value="Send">
	<input type="reset" value="Clear">
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:cycledude
ID: 37000006
@joeypolice

Thanks for the script mate, but like I say I have a pretty comprehensive one I developed myself, which uses jquery and php... I am more than happy with it, just getting wordpress to post to the same page is my problem.

0
 
LVL 6

Expert Comment

by:joeypolice
ID: 37000029
Sorry, I misunderstood.  :)
0
 

Author Comment

by:cycledude
ID: 37000039
@joeypolice

No problem, thanks for your help ;o)
0
 
LVL 17

Assisted Solution

by:jrm213jrm213
jrm213jrm213 earned 1200 total points
ID: 37000054
try changing the code for the post action to

the_permalink() instead of ''

<form id='contactform' method='post' action='<?php the_permalink();?>'>

also are  you doing this with a template page? Or did you create your form in the html editor of the page?
0
 

Author Comment

by:cycledude
ID: 37000097
@jrm213jrm213:

Thanks, tried it but it is the same....

this link has some info, but tried that and I get no page content other than the header when the form returns...

http://wordpress.org/support/topic/bug-found-forms-posting-to-itself

0
 

Author Comment

by:cycledude
ID: 37000117
@jrm213jrm213:

I am developing the page directly in the template, not in wordpress at all..

In wordpress I have a page called contact which is using the the template that I am manipulating in my dev tool

0
 

Author Comment

by:cycledude
ID: 37000136
I have basically taken my contact from from my existing (non wordpress) website and pasted the code into the template-file... maybe this can't be done this way?

0
 

Author Comment

by:cycledude
ID: 37000173
weird, this simple code works

<?php echo 'We have got: ' . $_POST['f1'] . ''; ?>
<form action="" method="POST">
<input type="text" name="f1" value="test"/>
<input type="submit" name="submit" value="Submit"/>
</form>

Open in new window

0
 

Author Comment

by:cycledude
ID: 37000207
ok I am narrowing it down to an error in the php somewhere...
0
 

Assisted Solution

by:cycledude
cycledude earned 0 total points
ID: 37000244
ok, I ahve found the culprit

if (!inStr("@",$email))

I am testing for an '@' symbol in the email address, this is throwing the page out... any ideas why? it works fine in standard website format?

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 37000260
what do you mean it is throwing the page out?
0
 

Accepted Solution

by:
cycledude earned 0 total points
ID: 37000266
oh boy, I just remembered... it's my own function, which I have not included!

job done

thanks for the help



0
 

Author Closing Comment

by:cycledude
ID: 37023060
script would have worked had I included the inStr function!

doh!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question