Redundant Scripts

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Redundant Scripts

Post by Pavilion »

Hello Everyone:

I've a question about how to handle redundant scripts. Following is a synopsis of the issues:
  1. User starts a discussion topic and may (or may not) want to invite several participants &/or add attachments.
  2. There are three buttons
    • Save Topic - processtopic_1.php
    • Save Topic and email invitations to your participants - processtopic_2.php
    • save Topic and add attachments - processtopic_3.php
  3. As you can imagine the script to "save topic" is the same line-by-line.
So... to avoid maintenance headaches, can I just include '.../root/topic/processtopic_1.php' in processtopic_2.php and processtopic_3.php?

And ... if I include file 1 in 2 and 3, will the results carry through 2 and 3 back to the original file?

Also... if I include file 1 in 2 and 3, are there things I should be aware of in setting up the files?

Thanks Much:

Pavilion
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Redundant Scripts

Post by Celauran »

These don't necessarily need to be sent to three different pages. One page will suffice and what gets processed can be determined by a series of if statements. Moreover, whether you use one processing page or several, you can break the actual processing into functions to avoid duplication of code.
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Redundant Scripts

Post by Pavilion »

Celauran wrote:These don't necessarily need to be sent to three different pages. One page will suffice and what gets processed can be determined by a series of if statements. Moreover, whether you use one processing page or several, you can break the actual processing into functions to avoid duplication of code.
Hello Celauran:

Thank you for jumping in here. Your advice is always welcome.

In theory - I know it is possible to streamline these processes. I'm just not familiar enough with php and jQuery here to do it right. So... here's what I'm currently thinking, and I'll adjust as needed.

All the buttons I listed in the first post are handled with jQuery listeners. Each of those jQuery functions trigger one of the php processing files.

You've mentioned that one page will suffice and I can use if statements to manage proper execution. But... that means I need to send something to the php file for use in this process. ..... So.... would it be possible for me to do the following?

Instead of three buttons, have only ONE save button topic button - which will post to the php processing file. Then change the following buttons to checkboxes..
  • Save Topic and email invitations to your participants - processtopic_2.php
  • save Topic and add attachments - processtopic_3.php
User can select either/or/both check boxes. Save button jQuery function can grab true/false values and pass those to the php processing file to use in the IF statements?????

On the surface this looks like a workable solution. Although my .post{} is already passing multiple arrays. It looks as follows:

Code: Select all

$.post("addressbk_data_3.php",{[color=#0040FF]bind_topic:topic_array, bind_participants:rowOwner_array, bind_emails:email_array[/color]},function(data){
var_returnData = $.parseJSON(data);
var_postID = var_returnData.post_id;
var_topicID = var_returnData.topic_id;
});
$.post("addressbk_data_3.php",{bind_topic:topic_array, bind_participants:rowOwner_array, bind_emails:email_array} .. passes topic_array, rowOwner_array, email_array. Every single one of these arrays are used to INSERT topic/participants data. The email_array is used for sending email invitations.

It should be possible for me to pack the true/false values right into topic_array - because this array already has a one-to-many relationship to participants and emails. So, when I "unwrap" the $_POST['bind_topic"], I can just extract appropriate true/false values there.....?????

Celauran - I know this post is more me thinking through things than asking specific instruction. But... am I heading in the right direction?

Thanks Much:

Pavilion
Post Reply