Jump to content

*solved function improper parameters?


Ninjakreborn

Recommended Posts

I have this
[code]<?php
function select($name, $label, $value, $priority) {
if ($priority == 1) {
$select = "selected=\"selected\"";
}
echo "<td style=\"text-align:right;\"><input name=\"{$name}\" type=\"checkbox\"
value=\"{$value}\" {$select} /></td>\n";
echo "<td style=\"text-align:left;\"><label for=\"{$name}\">{$label}</label></td>\n";
}
?>[/code]

I am calling it in multiple places, like
[code]<?php
select("actiontaken[goaround]", "Go Around", "Go Around", 0);
?>
[/code]
I feed it either 0-1 depending on the situation, and it's returning
[quote]Warning: Missing argument 4 for select() in /home/ninksafe/public_html/master/config/functions/validation.inc.php on line 84[/quote]
I don't understand why the error is appearing there?
Link to comment
Share on other sites

I'm not sure why you're getting that warning message, but I would change your code slightly to make the 4th parameter optional and pass it the boolean "true" or "false".
Function:
[code]<?php
function select($name, $label, $value, $priority=false) { // if the 4th parameter is not specified when invoking the procedure, it will default to "false"
$select = ($priority)?$select = 'selected="selected"':''; // why escape the double quotes when you can enclose the enitire string in single quotes
echo '<td style="text-align:right;"><input name="' . $name . '" type="checkbox"
value="' . $value . '" ' . $select . '/></td>' . "\n";
echo '<td style="text-align:left;"><label for="' . $name . '">' . $label . '</label></td>' . "\n";
}
?>[/code]

Invocation:
[code]<?php
select('actiontaken[goaround]', 'Go Around', 'Go Around');
?>[/code]

So, what was the problem?

Ken
Link to comment
Share on other sites

Well I had solved it, but now I see 2 new things you mentioned I didn't know, I will keep those in mind and play with them, I knew about the quote's, but I always used double because you can't extrapolate with singlle, but i have also started using concatenations (excuse spelling, don't feel like looking it up), I started using those so single quotes might be the way to go.

Thanks again for the advice.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.