Q: How do I remove registration form fields?
Posted: 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:
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.
3. Now you need to EDIT the controller file to remove the error checking:
4. FIND and REMOVE the validation code. All validation is done in the "validate" function towards the bottom. Find and remove the following:
That completes the necessary changes for the account/register step.
5. EDIT the checkout/register template file:
6. FIND and REMOVE the actual form field:
6. (a) FIND the closing </form> tag and BEFORE, insert:
7. EDIT the associated controller.
8. FIND and REMOVE the validation check:
That completes the necessary changes for the checkout/register step.
9. EDIT the checkout/guest template file:
10. FIND and REMOVE the actual form field:
10. (a) FIND the closing </form> tag and BEFORE, insert:
11. EDIT the associated controller.
12. FIND and REMOVE the validation check:
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.
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
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>
Code: Select all
catalog\controller\account\register.php
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');
}
5. EDIT the checkout/register template file:
Code: Select all
catalog/view/theme/YOURTHEME/template/checkout/register.tpl
Code: Select all
<span class="required">*</span> <?php echo $entry_telephone; ?><br />
<input type="text" name="telephone" value="" class="large-field" />
<br />
<br />
Code: Select all
<input type="hidden" name="telephone" value="" class="large-field" />
Code: Select all
catalog/controller/checkout/register.php
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');
}
9. EDIT the checkout/guest template file:
Code: Select all
catalog/view/theme/YOURTHEME/template/checkout/guest.tpl
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 />
Code: Select all
<input type="hidden" name="telephone" value="<?php echo $telephone; ?>" class="large-field" />
Code: Select all
catalog/controller/checkout/guest.php
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');
}
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.