extra fields in contact form

pending (6 posts) (2 voices)

  1. Firstly, though somewhat harder to navigate through than some other themes, let me just say I'm very impressed with the excellent theme.

    I'd like to ask about adding extra fields (phone) to the contact form widget. I've seen the other posts about using the contact7plugin, however I'd like to avoid using plug-ins where possible. I've already subtracted the website field easily enough from comments.php, and have narrowed down the two contact forms where changes need to be made.

    Widgets.php

    <p><input type="text" name="phoneNumberWidget" id="phoneNumberWidget" value="<?php if(isset($_POST['phoneNumberWidget']))  echo $_POST['phoneNumberWidget'];?>" class="requiredField textfield<?php if($phoneError != '') {echo ' inputError';} ?>" size="36" tabindex="5" /><label class="textfield_label" for="phoneNumberWidget">Phone No. *</label></p>

    Having inputted this into the widgets.php form, I was expecting a new field to pop up but it hasn't. (FYI, name is tabindex 4, phone is 5, email is 6 and comments 7)

    Regardless, in order to validate the form I also added this code too....

    submit-widget.php

    //Check to make sure sure that a valid phone number is submitted
    	if(trim($_POST['phoneNumberWidget']) === '')  {
    		$phoneError = 'You forgot to enter your Phone Number.';
    		$hasError = true;
    	} else if (!eregi("^[0-9_-]{14}$", trim($_POST['phoneNumberWidget']))) {
    		$phoneError = 'You entered an invalid phone number.';
    		$hasError = true;
    	} else {
    		$phone = trim($_POST['phoneNumberWidget']);
    	}

    I am missing something here..?

    Posted 11 months ago #
  2. Elliott
    Support

    Hello IntMilkBrilliant,

    I added your changes to my XAMPP setup and the phone field displayed fine. I didn't test the actual submission but if you want the phone number to appear in your email then you will need to append it to your message by changing line 62 (approximately),

    $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";

    To this,

    $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nComments: $comments";

    Is the phone field not showing up at all for you?

    Posted 11 months ago #
  3. Hi Elliot,

    Many thanks for your quick reply. The support service is rather exceptional here, which is good!

    Anyway, clearly I was missing something. After checking the next obvious place (theme-functions.php) it is now showing in the contact form. I haven't tested the send properties as yet, however for anybody else who wishes to add extra fields, the following code and their locations is:

    theme-functions.php

    $out .= '<p><input type="text" name="phoneNumber" id="phoneNumber" value="';
    
    		if(isset($_POST['phoneNumber'])) {
    			$out .= $_POST['phoneNumber'];
    		}
    		$out .= '"';
    		$out .= ' class="requiredFieldContact textfield';
    
    		if($phoneError != '') {
    			$out .= ' inputError';
    		}
    		$out .= '"';
    		$out .= ' size="22" tabindex="2" /><label class="textfield_label" for="phoneNumber">Phone No. *</label></p>';

    submit.php

    //Check to make sure sure that a valid phone number is submitted
    	if(trim($_POST['phoneNumber']) === '')  {
    		$phoneError = 'You forgot to enter your Phone Number.';
    		$hasError = true;
    	} else if (!eregi("^[0-9_-]{14}$", trim($_POST['phoneNumber']))) {
    		$phoneError = 'You entered an invalid phone number.';
    		$hasError = true;
    	} else {
    		$phone = trim($_POST['phoneNumber']);
    	}

    $body = "Name: $name \n\nPhone: $phone \n\nEmail: $email \n\nComments: $comments";

    Attachments

    1. Untitled.png (45.7 KB, 4 downloads) 11 months old
    Posted 11 months ago #
  4. UPDATE:

    Message was successfully sent! Will update after received msgs.

    Posted 11 months ago #
  5. Elliot,

    FYI, adding an extra field to the contact form stops it from being delivered to the recipient.

    Posted 11 months ago #
  6. Elliott
    Support

    If possible then send us a link to your site IntMilkBrilliant.

    Posted 11 months ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme