override div in extended class

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
grNadpa
New php-forum User
New php-forum User
Posts: 24
Joined: Fri Dec 02, 2016 8:32 am

Sun Aug 12, 2018 8:07 am

I have two nearly identical forms: Billing and Payment. So I would like my payment class form to inherit from the Billing form. I am familiar with overriding functions, but not sure if I can easily override code within a function.

Specifically, in the Billing View, I provide the client with four form submit options:

Code: Select all

 <div id="subdiv">
    <span><input type="submit" value="Post+Invoice" name="both" /></span>
    <span><input type="submit" value="Post Only" name="post" /></span>
    <span><input type="submit" value="Invoice Only" name="invoice" /></span>
    <span><input type="submit" value="Cancel" name="bail" /></span>
 </div> <!-- subdiv -->
But in the Payment, I want to provide only two:

Code: Select all

 <div id="subdiv">
    <span><input type="submit" value=Allocate" name="allocate" /></span>
    <span><input type="submit" value="Cancel" name="bail" /></span>
</div> <!-- subdiv -->
The options that occur to me are (1) create a php if statement that checks whether this is a billing or a payment (which violates encapsulation rules I believe)

Code: Select all

 <div id="subdiv">
 <?php if($this->subtitle == "billing") { ?>
    <span><input type="submit" value="Post+Invoice" name="both" /></span>
    <span><input type="submit" value="Post Only" name="post" /></span>
    <span><input type="submit" value="Invoice Only" name="invoice" /></span>
    <span><input type="submit" value="Cancel" name="bail" /></span>
  <?php } else { ?>
    <span><input type="submit" value=Allocate" name="allocate" /></span>
    <span><input type="submit" value="Cancel" name="bail" /></span>
 <?php } // end ifelse billing ?>
 </div> <!-- subdiv -->
or (2) create a Public Function to be overridden depending on the View invocation.

Code: Select all

 <div id="subdiv">
<?php $this->BuildSubmit() ?>
</div> <!-- subdiv -->
I plan to opt for the latter, but wonder if there is better approach.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 755
Joined: Mon Feb 22, 2016 5:52 pm

Mon Aug 13, 2018 9:16 am

Just show an itemised bill using a well designed display, i.e. items, sub total (maybe), post, tax and total; it gets too confusing otherwise.

grNadpa
New php-forum User
New php-forum User
Posts: 24
Joined: Fri Dec 02, 2016 8:32 am

Tue Aug 14, 2018 9:13 am

hyper wrote:
Mon Aug 13, 2018 9:16 am
Just show an itemised bill using a well designed display, i.e. items, sub total (maybe), post, tax and total; it gets too confusing otherwise.
Thank you. But that was not my question. This is an inheritance/polymorphism challenge:
I would like my payment class form to inherit from the Billing form. I am familiar with overriding functions, but not sure if I can easily override code within a function.

Post Reply