[wp-testers] POST variables with Wordpress Pages (Using RC-2)

Jamie Talbot wphackers at jamietalbot.com
Sun Dec 18 12:55:08 GMT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bryan Veloso wrote:
> Can you tell us how you did that? Since I'm having trouble making a
> contact form work as well. :)

Sure thing...

Nothing too fancy, it's just a simple form that passes POST vars to
itself...  Make sure you change the action attribute on the form to the
URL of the page.  I can't remember exactly, but using PHP_SELF didn't
work IIRC, but I might be lying...  There's a bit of javascript to
restrict the length of a phone message too, but it's not too interesting
for most people I think, so I removed it.  Mail me offline if you want
that too...

Hope this helps!

Jamie.

<div class="boxout" id="contactme">
<h4>Contact Me</h4>
<p>You can now either email me or send short messages direct to my phone
in Japan!</p>

<?php

if ($_POST['jt_send'])
{
  $name = $_POST['jt_name'];
  $from = $_POST['jt_address'];
  $message = $_POST['jt_message'];

  if ($_POST['jt_mode'] == "phone")
  {
    $to = "myphone at myemail.address";
  }
  else
  {
    $to = "regularemail at myemail.address";
  }

  $headers = "From: $from";
  if (isset($_POST['jt_cc'])) $headers .= "\nCC: $from\n";

  if (mail($to, "Message from $name (jamietalbot.com)", $message,
$headers) == 1)
  {

?>

<p class="highlight">Thanks for your message!  I'll get back to you as
soon as I can.</p>

<?php

  }
  else
  {

?>

<p class="error">Sorry, there was a problem sending your message.</p>

<?php
  }
}

?>

<form id="contact" action="http://jamietalbot.com/about/#contactme"
method="post">
<p>
<input id="phone" type="radio" value="phone" checked="checked"
name="jt_mode" /><label for="phone">Phone</label>
<input id="email" type="radio" value="email" name="jt_mode" /><label
for="email">Email</label>&nbsp;
<input class="textbox" id="mlength" type="text" value="160"
name="mlength" disabled="disabled" /><label for="mlength"> Length</label>
</p>
<p><label for="name">Name:</label><br /><input class="textbox" id="name"
 name="jt_name" /></p>
<p><label for="address">Email:</label><br /><input class="textbox"
id="address" name="jt_address" /></p>
<p><label for="message">Message:</label><br /><textarea id="message"
name="jt_message" rows="10" cols="10"></textarea></p>
<p><input id="cc" type="checkbox" value="cc" name="jt_cc" /><label
for="cc"> Send a copy to yourself</label></p>
<p><input class="button" type="submit" value="Send" name="jt_send" /></p>
</form>
</div>

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDpVwsrovxfShShFARAjIYAJsEnwRWjx0s3dDIjw8kqk3Fl9j95gCeJqsd
6mXT1RR3gYPR+q8ekZU+BWA=
=/qHA
-----END PGP SIGNATURE-----


More information about the wp-testers mailing list