Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Required fields

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-12-2003, 10:25 AM
 
rfcomponents.co.uk rfcomponents.co.uk is offline
 

Member
  
Join Date: Jun 2003
Posts: 19
 

Default Required fields

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

Many Thanks
Reply With Quote
  #2  
Old 06-27-2003, 08:51 AM
 
davesphoto davesphoto is offline
 

Member
  
Join Date: May 2003
Posts: 24
 

Default

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.
Reply With Quote
  #3  
Old 06-27-2003, 10:34 AM
 
davesphoto davesphoto is offline
 

Member
  
Join Date: May 2003
Posts: 24
 

Default

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.
Reply With Quote
  #4  
Old 07-16-2003, 05:39 AM
 
sunnyland sunnyland is offline
 

Advanced Member
  
Join Date: Jul 2003
Posts: 41
 

Default Where is the include file?

How can I find the file: include/help.php ?
Reply With Quote
  #5  
Old 07-16-2003, 05:47 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

ftp into your server and look through the files
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #6  
Old 07-29-2003, 09:39 AM
 
spingary spingary is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 51
 

Default 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
Reply With Quote
  #7  
Old 12-06-2003, 02:22 AM
 
assassin88 assassin88 is offline
 

Newbie
  
Join Date: Dec 2003
Posts: 6
 

Default 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
Reply With Quote
  #8  
Old 12-06-2003, 07:36 AM
 
spingary spingary is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 51
 

Default 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
Reply With Quote
  #9  
Old 03-22-2005, 05:40 PM
 
pwd88 pwd88 is offline
 

Advanced Member
  
Join Date: Dec 2004
Posts: 80
 

Default

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
__________________
XCart 4.0.18 Gold
X-Giftregistry
Neon light
Fashion mosaic
Tabbed product menu
Reply With Quote
  #10  
Old 03-22-2005, 06:22 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

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.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:49 AM.

   

 
X-Cart forums © 2001-2020