Jump to content

ELSE>IF TERNARY


Omzy

Recommended Posts

Basically I have a text input form which is built up from an array called $fields:

 

$fields=array(
  'name'=>array('Contact Name', '1', '25'),
  'company'=>array('Company Name', '1', '25'),
  'phone1'=>array('Tel Number 1', '1', '25'),
  'email'=>array('Email Address', '1', '35'),
  'url'=>array('Website URL', '0', '35'),
);

foreach($fields as $key => $value)
{
     echo '
   <b>'.$value[0].'</b>
   <input type="text" name="'.$key.'" value="', isset($_POST[$key]) ? $_POST[$key] : null ,'" size="'.$value[2].'"/>
  ';
}

 

As you can see the VALUE attribute is null upon page load or otherwise populated with its POST value if the form gets posted and has to be re-displayed.

 

This all works fine, however I need to extend the ternary statement to do an 'ELSE>IF' type operation. Basically the default value for the field 'url' needs to be 'http://' upon page load. I have tried several different ways of doing this but it just won't work for me!

 

Any ideas anyone?

Link to comment
https://forums.phpfreaks.com/topic/170498-elseif-ternary/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.