Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Tue Feb 28, 2006 1:14 pm Reply with quote

I am puting together another module I need for a gaming site. I have been looking at the Content and Download modules like Montego suggested to get a feel for how they are constructed.

The main admin/index.php will house all my forms and functions in the same page. The main function is called campaign () and has all my forms in it. Each form has its own op= for example and calls another function.

Code:
."<td align=\"center\">[ <a href=\"".$admin_file.".php?op=editcampaign&amp;cid=$cid\">" . _EDIT . "</a>]</td><tr>";


editcampaign () then will process any inputs from the campaign() function.

If I do any validations, should I do these in campaign () before I call editcampaign(). Should editcampaign only be used for inserting or updating records via a
Code:
$db->sql_query("UPDATE " . $prefix . "_
command?

From what I remember from some college programing classes a function will alway return a vaue. I just need the function to update or insert records.

From my example above how does the function editcampaign () get variables passed to it from campaign().

I will have other functions such as

function addmap($mid, $map_name, $map_image)


I am such a noob with functions.
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Tue Feb 28, 2006 1:58 pm Reply with quote

Functions only return a value if you tell them to, via the return variableName; or return value; type statement. There are different ways to update variables passed to functions via the variable scope (global or local). Read up on this at http://us2.php.net/manual/en/language.functions.php.

Now to your point of where you do what, I would recommend that you do all validations that are global in scope in campaign and all that are local in the subFunction (editcampaign). In other words if you have 6 functions and they all hava variables passed which are the same, validate the variable before calling the function. In the case(s) where a function is unique in the arguments passed to it, validate those locally in the function.

Having said that, there is certainly nothing wrong with having a function that does ALL validations!
 
View user's profile Send private message
Donovan







PostPosted: Tue Feb 28, 2006 3:28 pm Reply with quote

So then this code with validation (if correct Very Happy ):

Code:
/* Add a New Campaign */

    OpenTable();
   echo "<center><font class=\"option\"><b>" . _ADDCAMPAIGN . "</b></font></center><br>"
   ."<hr>"
   ."<table border=\"1\" width=\"100%\" align=\"center\"><tr>"
    ."<form method=\"post\" action=\"".$admin_file.".php\">"   
   ."" . _NAME . ": <input type=\"text\" name=\"title\" size=\"30\" maxlength=\"100\"><br>"      
   ."" . _DESCRIPTION . ":<br><textarea name=\"cdescription\" cols=\"60\" rows=\"10\"></textarea><br>"   
   ."<input type=\"hidden\" name=\"op\" value=\"addcampaign\">"
   ."<input type=\"submit\" value=\"" . _ADD . "\"><br>"
   ."</form>"
   ."</td></tr></table>";
   if ($op == "addcampaign") {
   $title = $_POST['title'];
   $cdescription = $_POST['cdescription'];
   if (empty($title)){
   echo "You must enter a title for the campaign.";
      }
   if (empty($cdescription)){
   echo "You must enter a description for the campaign.";
      }
   }    CloseTable();


Would pass to the following values to this function.

Code:
function addcampaign($title, $cdescription) {

    global $prefix, $db, $admin_file;
    $db->sql_query("INSERT INTO " . $prefix . "_eto_campaigns VALUES (NULL, '$title', '$cdescription')");
    Header("Location: ".$admin_file.".php?op=campaign");
}
 
Raven







PostPosted: Tue Feb 28, 2006 5:36 pm Reply with quote

Yes, although you need to properly filter the POST content to avoid XSS vulnerabilities.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©