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
Share on other sites

I tried this:

 


value="', !isset($_POST[$key]) && $key=='url' ? 'http://' : isset($_POST[$key]) ? $_POST[$key] : null ,'"

 

But it gives me an error notice on page saying:

 

Undefined index:  url in ...

 

How is it undefinded?

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.