X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Required fields (https://forum.x-cart.com/showthread.php?t=3157)

rfcomponents.co.uk 06-12-2003 10:25 AM

Required fields
 
Please could someone tell me how to remove/edit the required field tabs in contact us also in checkout,

Many Thanks :D

davesphoto 06-27-2003 08:51 AM

I am wondering the same thing.

Seems silly to require people to enter their address just to ask you a question (and then to make it even more futile it doesn't even register them as a user). I would just dump it and make my own contact page, but I like people being able to enter that info, just not being required to.

davesphoto 06-27-2003 10:34 AM

This was easier than I thought once I found the right file. The contact mail sending is done by include/help.php. All you must do to make options not required is change code:

Code:

    $fillerror = (empty($contact["firstname"]) || empty($contact["lastname"]) || empty($contact["b_address"]) || empty($contact["b_city"]) || empty($contact["b_country"]) || empty($contact["b_zipcode"]) || empty($contact["phone"]) || empty($contact["email"]) || empty($contact["subject"]) || empty($contact["body"]));

to:

Code:

    $fillerror = (empty($contact["firstname"]) || empty($contact["lastname"]) || empty($contact["email"]) || empty($contact["body"]));

Now no address info is required. Emails go thru perfectly they just dont have any information in the fields that are not filled out that are no longer required.

Hope that is what you were looking for.

sunnyland 07-16-2003 05:39 AM

Where is the include file?
 
How can I find the file: include/help.php ?

shan 07-16-2003 05:47 AM

ftp into your server and look through the files

spingary 07-29-2003 09:39 AM

Easier way to remove required fields in contact form
 
The way to remove required fields from the contact form is to edit the include/help.php file and the skin1/help/contact.tpl file as mentioned in the previous posts.

However, I didn't want to edit the PHP file for fear of upgrade issues/headaches in the future. My method is to do this by adding some Javascript to the contact.tpl file.

The idea is this:

1) remove the asterisks of the fields you don't want required anymore
2) add our own javascript validation function that denies submission of the form if our required fields are not filled in
3) in that same validation function, set the fields that we no longer want required to a non-empty string if the user did not fill it out.

The javascript function looks like this:
Code:

function formSubmit(thisform)
{
        // The fields I want required are: firstname,lastname,email,phone,department,subject,message body
        // Since Department is never empty, we don't check for it.
        // The email validation is also called here to check for good email addresses
        // Note that you can ADD additional fields to be required here if you want!
        if ((thisform.firstname.value == "")||(thisform.lastname.value == "")||(!checkEmailAddress(thisform.email))        || (thisform.phone.value =="")||(thisform.subject.value=="")||(thisform.body.value==""))
        {
                alert ("Please fill out the required fields (denoted by *) before submitting the form!");
                return false;
        }
        else
        {
                // These are the other fields that X-Cart requires.  But, we don't want them to be required.
                // So, if the user did not fill in these fields, we simply set them to " " so that X-Cart won't complain.
                if (thisform.b_address.value == "")
                        thisform.b_address.value = " ";
                if (thisform.b_zipcode.value == "")
                        thisform.b_zipcode.value = " ";
                if (thisform.b_city.value == "")
                        thisform.b_city.value = " ";
                if (thisform.b_address.value == "")
                        thisform.b_address.value = " ";
                return true;
        }
}


We have to change our submit button to call that validation function from:
to

My complete contact.tpl file looks like this.
Code:

{* $Id: contactus.tpl,v 1.17.2.1 2003/02/11 09:03:02 svowl Exp $ *}
{literal}
<script>
function checkEmailAddress(field) {
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail) {
    return true;
} else {
        alert("E-mail address is invalid! Please correct");
        field.focus();
        field.select();
        return false;
    }
}

function formSubmit(thisform)
{
        // The fields I want required are: firstname,lastname,email,phone,department,subject,message body
        // Since Department is never empty, we don't check for it.
        // The email validation is also called here to check for good email addresses
        // Note that you can ADD additional fields to be required here if you want!
        if ((thisform.firstname.value == "")||(thisform.lastname.value == "")||(!checkEmailAddress(thisform.email))        || (thisform.phone.value =="")||(thisform.subject.value=="")||(thisform.body.value==""))
        {
                alert ("Please fill out the required fields (denoted by *) before submitting the form!");
                return false;
        }
        else
        {
                // These are the other fields that X-Cart requires.  But, we don't want them to be required.
                // So, if the user did not fill in these fields, we simply set them to " " so that X-Cart won't complain.
                if (thisform.b_address.value == "")
                        thisform.b_address.value = " ";
                if (thisform.b_zipcode.value == "")
                        thisform.b_zipcode.value = " ";
                if (thisform.b_city.value == "")
                        thisform.b_city.value = " ";
                if (thisform.b_address.value == "")
                        thisform.b_address.value = " ";
                return true;
        }
}
</script>
{/literal}
{if $smarty.get.mode eq "update"}
{$lng.txt_contact_us_header}
{/if}



{capture name=dialog}
{if $smarty.get.mode eq "update"}
<table width=100% border=0 cellspacing=0 cellpadding=2>
<form action="help.php?section=contactus&mode=update&action=contactus"  method=post name=registerform>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_username}</td>
<td></td>
<td nowrap>
<input type=text name=uname size=32 maxlength=32 value="{$userinfo.login}">
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_title}</td>
<td></td>
<td nowrap>
<select name=title>
{section name=title loop=$name_titles}
<option {if $userinfo.title eq $name_titles[title]}selected{/if}>{$name_titles[title]}</option>
{/section}
</select>
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_first_name}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=firstname size=32 maxlength=32 value="{$userinfo.firstname}">
{if $fillerror ne "" and $userinfo.firstname eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_last_name}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=lastname size=32 maxlength=32 value="{$userinfo.lastname}">
{if $fillerror ne "" and $userinfo.lastname eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_address}</td>
<td></td>
<td nowrap>
<input type=text name=b_address size=32 maxlength=64 value="{$userinfo.b_address}">
{if $fillerror ne "" and $userinfo.b_address eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_zip_code}</td>
<td></td>
<td nowrap>
<input type=text name=b_zipcode size=32 maxlength=32 value="{$userinfo.b_zipcode}">
{if $fillerror ne "" and $userinfo.b_zipcode eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_city}</td>
<td></td>
<td nowrap>
<input type=text name=b_city size=32 maxlength=64 value="{$userinfo.b_city}">
{if $fillerror ne "" and $userinfo.b_city eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_state}</td>
<td></td>
<td nowrap>
{if $states ne ""}
<select name=b_state size=1>
<option value="">{$lng.lbl_select_one}</option>
{section name=state_idx loop=$states}
<option value={$states[state_idx].state_code} {if $userinfo.b_state eq $states[state_idx].state_code}selected{/if}>{$states[state_idx].state}</option>
{/section}
</select>
{else}
<input type=text size=32 name=b_state maxlength=64 value="{$userinfo.b_state}">
{/if}
</td>
</tr>


<tr valign=middle>
<td class=FormButton>{$lng.lbl_country}</td>
<td></td>
<td nowrap>
<select name=b_country>
{section name=country_idx loop=$countries}
<option value={$countries[country_idx].country_code} {if $userinfo.b_country eq $countries[country_idx].country_code}selected{elseif $countries[country_idx].country_code eq $config.General.default_country and $userinfo.b_country eq ""}selected{/if}>{$countries[country_idx].country}</option>
{/section}
</select>
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_phone}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=phone size=32 maxlength=32 value="{$userinfo.phone}">
{if $fillerror ne "" and $userinfo.phone eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_fax}</td>
<td></td>
<td nowrap>
<input type=text name=fax size=32 maxlength=128 value="{$userinfo.fax}"></td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_email}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=email size=32 maxlength=128 value="{$userinfo.email}">
{if $fillerror ne "" and $userinfo.email eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_web_site}</td>
<td></td>
<td nowrap>
<input type=text name=url size=32 maxlength=128 value="{if $userinfo.url eq ""}http://{else}{$userinfo.url}{/if}"></td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_department}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<select name=department>
<option value="All" selected>{$lng.lbl_all}</option>
<option value="Partners">{$lng.lbl_partners}</option>
<option value="Marketing / publicity">{$lng.lbl_marketing_publicity}</option>
<option value="Webdesign">{$lng.lbl_web_design}</option>
<option value="Sales">{$lng.lbl_sales}</option>
</select>
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_subject}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=subject size=32 maxlength=128 value="{$smarty.get.prefill}{$userinfo.subject}">
{if $fillerror ne "" and $userinfo.subject eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td class=FormButton>{$lng.lbl_message}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<textarea cols=48 rows=12 name=body>{$userinfo.body}</textarea>
{if $fillerror ne "" and $userinfo.body eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>

<tr valign=middle>
<td></td>
<td></td>
<td nowrap>


{include file="buttons/submit.tpl"}
</td>
</tr>
<input type=hidden name=usertype value="{$usertype}">
</form>
</table>
{else}
{$lng.txt_contact_us_sent}
{/if}
{/capture}
{include file="dialog.tpl" title=$lng.lbl_contact_us content=$smarty.capture.dialog extra="width=100%"}


Fun, eh?

Gary

assassin88 12-06-2003 02:22 AM

cool scripting
 
Hey Gary,
looks cool...
Does this method kinda bypass the required fields in the help.php file? Will this work if I want to remove some of the fields in the contact.tpl file? or do all the fields have to stay there if u want it to work?

thanks,
Ben

spingary 12-06-2003 07:36 AM

Re: cool scripting
 
Quote:

Originally Posted by assassin88
Hey Gary,
Does this method kinda bypass the required fields in the help.php file? Will this work if I want to remove some of the fields in the contact.tpl file? or do all the fields have to stay there if u want it to work?
Ben


Kind of... instead of BYPASSING the idea is to go AROUND the required fields in help.php by using JS to set the ones we DON'T want to be required to a non-empty string.

If you want to remove a couple of fields (even the required ones), all you have to do is change them from text fields to hidden input fields.

Gary

pwd88 03-22-2005 05:40 PM

From what I have read, all these mod are about removing some unwanted fields in the contact us form, How do I add some fields if I want to use this contact us form for music student application form, I need the student to enter what time they want to book, what class, etc

balinor 03-22-2005 06:22 PM

This is a very old thread. In version 4, you can just go to General Settings/Contact Us Options and add as many extra fields as you want by using the dialog at the bottom. Same goes for the registration forms.


All times are GMT -8. The time now is 02:45 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.