Page 1 of 1

add field to contact form

Posted: Sat Sep 24, 2005 6:01 am
by Guest
What's the simplest way to go about this? I'd like to add a phone field.


TIA

Re: add field to contact form

Posted: Mon Sep 26, 2005 1:10 pm
by garvinhicking
1. Edit your "plugin_contactform.tpl" file of the plugin.
2. Place your "phone address" field somewhere in that file, most preferably into the table where the other fields are shown:

Code: Select all

        <tr>
            <td class="serendipity_commentsLabel"><label for="serendipity_commentform_phone">Phone</label></td>
            <td class="serendipity_commentsValue"><input type="text" id="serendipity_commentform_phone" name="serendipity[phone]" value="{$commentform_phone}" /></td>
        </tr>
3. Now edit the serendipity_event_contactform.php file.
4. Find this code:

Code: Select all

        $text = sprintf(A_NEW_COMMENT_BLAHBLAH, $serendipity['blogTitle'], $title)
              . "\n"
              . "\n" . USER . ' ' . IP_ADDRESS . ': ' . $_SERVER['REMOTE_ADDR']
              . "\n" . USER . ' ' . NAME       . ': ' . $fromName
              . "\n" . USER . ' ' . EMAIL      . ': ' . $fromEmail
              . "\n" . USER . ' ' . HOMEPAGE   . ': ' . $fromUrl
              . "\n"
              . "\n" . COMMENTS                . ': '
              . "\n" . $comment
              . "\n"
              . "\n" . '----';
and change this to:

Code: Select all

        $text = sprintf(A_NEW_COMMENT_BLAHBLAH, $serendipity['blogTitle'], $title)
              . "\n"
              . "\n" . USER . ' ' . IP_ADDRESS . ': ' . $_SERVER['REMOTE_ADDR']
              . "\n" . USER . ' ' . NAME       . ': ' . $fromName
              . "\n" . USER . ' ' . EMAIL      . ': ' . $fromEmail
              . "\n" . USER . ' ' . HOMEPAGE   . ': ' . $fromUrl
              . "\n" . USER . ' Phone: ' . $serendipity['POST']['phone']
              . "\n"
              . "\n" . COMMENTS                . ': '
              . "\n" . $comment
              . "\n"
              . "\n" . '----';
Note the new line with "Phone" in it. This piece of code will show the persons phone number inside your contact mail.

5. Find this line a few lines later:

Code: Select all

                    'commentform_url'            => htmlspecialchars(strip_tags($serendipity['POST']['url'])),
and change it to:

Code: Select all

                    'commentform_url'            => htmlspecialchars(strip_tags($serendipity['POST']['url'])),
                    'commentform_phone'            => htmlspecialchars(strip_tags($serendipity['POST']['phone'])),
This line of code will make sure that if a person enters the phone number and makes something else wrong, the form will be filled with his previous phone number.

[quote="Anonymous"]What's the simplest way to go about this? I'd like to add a phone field.

6. Save the files and be happy :)

Regards,
Garvin