Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How add fields to contact form? WordPress

  • SOLVED

Hello,
I would like to add more fields to "default Wp" contact form page.
Now we have: Name, email and messagge.

I wanna add fields in contact.php:

- Company
- Surname and Name
- Email
- Subject
- Messagge

SEND MESSAGGE (button)

How I shoud edit contact.php to do it? All this field must be included in receiver email.
Thank you!

<?php
/**
* Template Name: Contact
* The main template file for display contact page.
*
* @package WordPress
*/


/**
* if not submit form
**/

if(!isset($_GET['your_name']))
{

if(!isset($hide_header) OR !$hide_header)
{
get_header();
}

/**
* Get Current page object
**/
$page = get_page($post->ID);

/**
* Get current page id
**/

if(!isset($current_page_id) && isset($page->ID))
{
$current_page_id = $page->ID;
}

$page_sidebar = get_post_meta($current_page_id, 'page_sidebar', true);

if(empty($page_sidebar))
{
$page_sidebar = 'Contact Sidebar';
}

$caption_class = 'page_caption';

$caption_style = get_post_meta($current_page_id, 'caption_style', true);

if(empty($caption_style))
{
$caption_style = 'Title & Description';
}

if(!isset($hide_header) OR !$hide_header)
{
$page_button_title = get_post_meta($current_page_id, 'page_button_title', true);
$page_button_href = get_post_meta($current_page_id, 'page_button_href', true);
?>

<div class="page_caption">
<div class="caption_inner">
<div class="caption_header">
<h1 class="cufon"><?php echo the_title(); ?></h1>
</div>

<?php
if(!empty($page_button_title))
{
?>
<div style="float:right;margin:20px 20px 0 0">
<a class="button" href="<?php echo $page_button_href; ?>"><?php echo $page_button_title; ?></a>
</div>
<?php
}
?>
</div>
</div>

<div id="header_pattern"></div>

</div>

<?php
$pp_contact_display_map = get_option('pp_contact_display_map');

if(!empty($pp_contact_display_map))
{
$pp_contact_lat = get_option('pp_contact_lat');
$pp_contact_long = get_option('pp_contact_long');
$pp_contact_map_zoom = get_option('pp_contact_map_zoom');
?>
<div id="map_contact" style="width:100%;height:300px;"></div>
<script>
$j(document).ready(function(){
$j("#map_contact").gMap({ controls: false, scrollwheel: false, zoom: <?php echo $pp_contact_map_zoom; ?>, markers: [ { latitude: '<?php echo $pp_contact_lat; ?>', longitude: '<?php echo $pp_contact_long; ?>'} ] });
});
</script>
<?php
}
?>

<!-- Begin content -->
<div id="content_wrapper">

<div class="inner">

<!-- Begin main content -->
<div class="inner_wrapper">

<?php
}
?>

<div class="sidebar_content">
<?php
if(!isset($hide_header) OR !$hide_header)
{
if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<?php the_content(); break; ?><br/><br/>

<?php endwhile;
}
?>

<form id="contact_form" method="post" action="<?php echo curPageURL(); ?>">
<p>
<label for="your_name">Nome e Cognome</label><br/>
<input id="your_name" name="your_name" type="text" style="width:94%"/>
</p>
<p style="margin-top:20px">
<label for="email">Email</label><br/>
<input id="email" name="email" type="text" style="width:94%"/>
</p>
<p style="margin-top:20px">
<label for="message">Messaggio</label><br/>
<textarea id="message" name="message" rows="7" cols="10" style="width:94%"></textarea>
</p>
<p style="margin-top:20px">
<input type="submit" value="Invia Messaggio"/><br/>
</p>
</form>
<div id="reponse_msg"></div>
<br/><br/>

</div>

<div class="sidebar_wrapper">
<div class="sidebar_top"></div>

<div class="sidebar">

<div class="content">

<ul class="sidebar_widget">
<?php dynamic_sidebar($page_sidebar); ?>
</ul>

</div>

</div>
<br class="clear"/>

<div class="sidebar_bottom"></div>
</div>

<?php
if(!isset($hide_header) OR !$hide_header)
{
?>
</div>
<!-- End main content -->

<br class="clear"/>

</div>
</div>
<!-- End content -->


<?php get_footer(); ?>

<?php
}
elseif(!$pp_homepage_hide_right_sidebar)
{
?>

</div>
<!-- End main content -->

<br class="clear"/>

</div>

</div>
<!-- End content -->

<?php
}
?>

<?php
}

//if submit form
else
{

/*
|--------------------------------------------------------------------------
| Mailer module
|--------------------------------------------------------------------------
|
| These module are used when sending email from contact form
|
*/

//Get your email address
$contact_email = get_option('pp_contact_email');

//Enter your email address, email from contact form will send to this addresss. Please enter inside quotes ('[email protected]')
define('DEST_EMAIL', $contact_email);

//Change email subject to something more meaningful
define('SUBJECT_EMAIL', 'Email from www-bpe-electronics.it');

//Thankyou message when message sent
define('THANKYOU_MESSAGE', 'Grazie per averci contattato. Sarete ricontattati al più presto.');

//Error message when message can't send
define('ERROR_MESSAGE', 'Spiacenti. Qualcosa è andato storto! Ti preghiamo di riprovare più tardi.');


/*
|
| Begin sending mail
|
*/

$from_name = $_GET['your_name'];
$from_email = $_GET['email'];

$message = 'Nome e Cognome: '.$from_name.PHP_EOL;
$message.= 'Email: '.$from_email.PHP_EOL.PHP_EOL;
$message.= 'Messaggio: '.PHP_EOL.$_GET['message'];


if(!empty($from_name) && !empty($from_email) && !empty($message))
{
mail(DEST_EMAIL, SUBJECT_EMAIL, $message);

echo THANKYOU_MESSAGE;

exit;
}
else
{
echo ERROR_MESSAGE;

exit;
}

/*
|
| End sending mail
|
*/
}

?>


Answers (3)

2012-02-06

Gabriel Reguly answers:

Hi flaxy,

$1 won't get you much answers, if you can afford a bigger prize, please do it.

It is a favor you do for yourself ;-)

Plugins are a fast and secure way to do what you want, I would recommend these 2:

[[LINK href="http://wordpress.org/extend/plugins/contact-form-7/"]]http://wordpress.org/extend/plugins/contact-form-7/[[/LINK]]

[[LINK href="http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/"]]http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/[[/LINK]]

Regards,
Gabriel


flaxy comments:

How much you wont to edit all file?


Gabriel Reguly comments:

Hi Flaxy,

$40 would be a good prize for this task.

Regards,
Gabriel

2012-02-07

MDan answers:

Hello Flaxy,

I can do this work for $20.

<strong>Daniel </strong>


flaxy comments:

Ok, great! How can I send you file or you can Just edit my code?


flaxy comments:

Now my question is 21$. But I wanna be sure everything works perfectly :)

Daniel you need contact.php file? Or ftp access?


MDan comments:

Hi flaxy,

Please send me PM with admin access to your website:
http://www.wpquestions.com/user/profile/id/3278

Thanks,
Daniel


flaxy comments:

I have sent all information.

2012-02-06

Albert Shala answers:

Try adding your fields and declare your variables for submitting.


<p>
<label for="subject">Subject</label><br/>
<input id="subject" name="subject" type="text" style="width:94%"/>

</p>



and use this to submit

$subject = $_GET['subject'];
$message.= 'Email: '.$subject.PHP_EOL.PHP_EOL;


flaxy comments:

Can you please edit that code with adding all listed fields?