At 02:04 PM 11/26/2001 +0200, Rudi Ahlers wrote:
How would I be able to change a variable from the input in a checkbox? I
need to write an sms script, that would be able to sms to three different
providers, and I only want the use to type in the phone number. Thus, if he
types in 083xx, it should goto provider 1, if he types in
082xx, it should goto provider 2, and if he types in 084xx,
it should goto provider 3. I have a simple mail script, with $phone for the
phone number variable, and this is the one that needs to change.
Rudi Ahlers
UNIX Specialist and Web Developer
Bonzai Web Design - http://www.bonzai.org.za
Cell: 082 926 1689
Rudi,
Try this - a function definition, followed by where I use it further down the
page.
Miles
// is_checked
// preserves status of previous selection of radio buttons or checkboxes
// when page redisplays by inserting checked into appropriate line of
option group
// used in a group of radio buttons or checkboxes.
// usage: is_checked( $radio_val == 'open')
// CQA Consulting 2000
//
function is_checked( $opt_expression )
{
if( $opt_expression )
{
$retval = checked;
}
else
{
$retval = ;
}
echo $retval;
}
//end of function is_checked
And then further down the page, in a form, these radio buttons:
td Display:/td
td input type=radio name=AuctionChoice value = open ? is_checked(
$AuctionChoice=='open') ? Open /td
td input type=radio name=AuctionChoice value = closed ?
is_checked( $AuctionChoice=='closed') ? Closed /td
td input type=radio name=AuctionChoice value = both ? is_checked(
$AuctionChoice=='both') ? Both /td
The use of checked is not good terminology, because it implies a
checkbox. You can replace AuctionChoice with PhoneChoice, and open ...
both with your phone numbers or ISP id's and you're off to the races.
Now these next bits are out of sequence. They properly belong between the
function definition and the display fragment, but are inserted here so you
can see how I use the $AuctionChoice when it is read when the page is
reloaded. It's used to build up a WHERE clause for a SELECT.
switch( $AuctionChoice )
{
case open:
$auction_where = lOnAuction = 1 ;
break;
case closed:
$auction_where = lOnAuction = 0 ;
break;
default:
unset( $auction_where);
}
and there is also a choice coming from a combo box, which returns a string
representing a class, hence $class_where, used like so:
// where clause fragment for the chosen class
if( $ClassChoice )
{
$class_where = nClass = $ClassChoice ;
}
The WHERE condition for the select is put together like this:
// assemble the _where clause fragments into a
// coherent WHERE condition
if( $auction_where $class_where )
{
$sql_where = WHERE $auction_where AND $class_where ;
}
elseif( $auction_where)
{
$sql_where = WHERE $auction_where ;
}
elseif( $class_where )
{
$sql_where = WHERE $class_where ;
}
// now put the select statement together, test for results and
display accordingly
$sql = SELECT * FROM item $sql_where order by cItemId;
There's probably someone on the list who can do it with fewer lines, but I
find this clear, and it accommodates all my conditions, and if no choices
are made $sql_where does not exist and the SELECT is still valid. I still
find the statelessness of web pages strange, how variables just cease to
exist next time around if you don't explicitly pass them.
If this is overkill, or I missed the mark completely, apologies. Otherwise,
I hope you find it useful.
Miles Thompson
http://www.cqagroup.ca
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]