Post by Qphoria » Mon Nov 21, 2011 11:12 pm

Q: How do I remove registration form fields? I try to remove them from the template but an error still shows.

A:
Form fields in OpenCart use php-based error handling. This means that if you remove a field from the template, the php code still looks for that field. If it doesn't find a value for it, it throws an error.

For non-required form fields like fax, company, and address_2, you can simply remove them from the tpl and they won't be missed.

But to properly remove a required form field, you need all the pieces to be removed. At this time, there are 3 spots where people can register. "account/register", "checkout/register", and "checkout/guest". OpenCart needs to work on combining the registration/checkout area to combine all into one step. The account and checkout system needs a bit of an overhaul to be simplified.

Anyway, to make the necessary changes... Determine which field you want to remove.

For this example, I will be removing the "telephone" field.

(v1.5.1)
1. Edit the first template file to remove the actual field from the html:

Code: Select all

catalog/view/theme/YOURTHEME/template/account/register.tpl
2. FIND and REMOVE the form field and surrounding table code. You should be able to follow the pattern of the file based on the tabbing.

Code: Select all

<tr>
  <td><span class="required">*</span> <?php echo $entry_telephone; ?></td>
  <td><input type="text" name="telephone" value="<?php echo $telephone; ?>" />
    <?php if ($error_telephone) { ?>
    <span class="error"><?php echo $error_telephone; ?></span>
    <?php } ?></td>
</tr>
3. Now you need to EDIT the controller file to remove the error checking:

Code: Select all

catalog\controller\account\register.php
4. FIND and REMOVE the validation code. All validation is done in the "validate" function towards the bottom. Find and remove the following:

Code: Select all

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
          $this->error['telephone'] = $this->language->get('error_telephone');
} 
That completes the necessary changes for the account/register step.

5. EDIT the checkout/register template file:

Code: Select all

catalog/view/theme/YOURTHEME/template/checkout/register.tpl
6. FIND and REMOVE the actual form field:

Code: Select all

<span class="required">*</span> <?php echo $entry_telephone; ?><br />
<input type="text" name="telephone" value="" class="large-field" />
<br />
<br />
6. (a) FIND the closing </form> tag and BEFORE, insert:

Code: Select all

<input type="hidden" name="telephone" value="" class="large-field" />
7. EDIT the associated controller.

Code: Select all

catalog/controller/checkout/register.php
8. FIND and REMOVE the validation check:

Code: Select all

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
	$json['error']['telephone'] = $this->language->get('error_telephone');
}
That completes the necessary changes for the checkout/register step.

9. EDIT the checkout/guest template file:

Code: Select all

catalog/view/theme/YOURTHEME/template/checkout/guest.tpl
10. FIND and REMOVE the actual form field:

Code: Select all

<span class="required">*</span> <?php echo $entry_telephone; ?><br />
<input type="text" name="telephone" value="<?php echo $telephone; ?>" class="large-field" />
<br />
<br />
10. (a) FIND the closing </form> tag and BEFORE, insert:

Code: Select all

<input type="hidden" name="telephone" value="<?php echo $telephone; ?>" class="large-field" />
11. EDIT the associated controller.

Code: Select all

catalog/controller/checkout/guest.php
12. FIND and REMOVE the validation check:

Code: Select all

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
	$json['error']['telephone'] = $this->language->get('error_telephone');
}
That completes the necessary changes for the checkout/guest step.

Now you should no longer see the telephone entry on any registration/checkout forms.

The process for 1.4.x is similar, but has code differences. If needed I will post that up but as we are working on improving this process, I am trying not to go too far back.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Sat Dec 10, 2011 12:51 pm

Don't remove the input fields, change their type from "text" to "hidden". Removing them will only cause errors, as no field is passed through to the db query in the model.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Johnathan » Sun Dec 11, 2011 12:03 am

Seems like this would be a good thing to add to the core at some point, so people could choose which fields to have.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by opencartArab » Sun Dec 11, 2011 1:56 am

fido-x wrote:Don't remove the input fields, change their type from "text" to "hidden". Removing them will only cause errors, as no field is passed through to the db query in the model.

+1

التعليمات باللغة العربية على الرابط التالي
https://www.opencartarab.com/docs
استضافة اوبن كارت العرب
https://host.opencartarab.com


Expert Member

Posts

Joined
Thu Apr 01, 2010 3:31 am

Post by fido-x » Mon Dec 12, 2011 12:39 am

Tutorial updated. Inserted items 6(a) and 10(a).

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia
Who is online

Users browsing this forum: No registered users and 1 guest