Jump to content

Recommended Posts

Hello All!

 

I have a page that asks if the data input by the user should be visible or not -- if yes, it appears on the page, if no, don't show it.

 

I was using a checkbox for this, but discovered that if the user tries to change it from checked to unchecked, it wasn't working correctly; so, I'm now trying a new dropdown function for this -- problem is, it's not saving the choice for each record now...and when you go in to update a record, the drop down is always blank vs. 'Yes' or 'No', depending on what the user selects...

 

How can I fix this?

 

Here's the call to the function in my form:

<?= true_false_dropdown('visible', ($current->getVisible() == 1)); ?>

 

And here's my function:

// true / false dropdown
function true_false_dropdown($name, $default="", $on_change="")
{
  $tf = array	(
              "false" => "Yes",
	      "true" => "No"
		    );
  return (array_dropdown($tf, $name, $default, true, $on_change));						
}

 

 

If anyone could tell me how to fix this, I'd be most appreciative.

 

Thanks for your time and help!

-j.g.

Link to comment
https://forums.phpfreaks.com/topic/66916-newbie-need-help-w-function-change/
Share on other sites

OK - thanks.

 

Here's my code to Save it to the db:

if ($_POST['save'] == 'Save')
{
  $current->processPost($_POST);
  $current->setParent($parent_id);
  if ( (strlen($_FILES['FILE']['tmp_name']) > 0) && $_FILES['FILE']['error'] == 0)
  {
$file = new File();
$file->readInFile($_FILES['FILE']['tmp_name'], $_FILES['FILE']['name'], $_FILES['FILE']['name']);
$current->addFile($file);	
  }
header("Location: govt_relations_faq_updater.php?msg=".urlencode("'".$current->getTitle()."' Saved."));
exit;
}

 

My db col's/types pertaining to this:

 

content_id - int(11) unsigned

visible - tinyint(1) unsigned

 

 

Is there any additional info that I'm missing that I could provide? If so, just let me know.

 

Thanks!

-j.g.

 

The code you have posted helps little to resolve your problem... it looks like you use some kind of framework or at least some classes / function which we don't know of / about.

 

Basically I have no idea about what your code does... it seems like it handles a file upload? Shouldn't it just write/update a single value in a specific row in your database...

 

E.g. set the "Show private data" to "Yes" or "No" for a user?

Sorry.

 

Everything is working (file uploads, save title, description, etc) except for the 'Visible' part...

 

I cannot get the dropdown to work correctly.

 

If you're on the page to enter data, the dropdown is visible, but blank - you can either select 'Yes' or 'No' from it -> but if I select 'No', then save it, and click 'Update' on the same record, all the info I've entered is there, but the dropdown is blank (Not saving the 'No').

 

And, the same with the 'Yes' --> and if it's set to 'Yes' I want to display it on another page, which I'll worry about after getting this issue resolved....I just want to get this backend stuff working first...  I just first need to get this value to be saved and then able to switch the values (if 'Yes', change it to 'No', etc).

 

 

What other information can I provide to help you help me? :)

 

Thanks again!

-j.g.

So basically you would like your drop-down menu to remember what option the user is currently using?

 

E.g. if the user has selected 'No' then you would like the drop-down menu to display / preselect 'No' the next time the user visits his profile editor?

Of course you can change your function to "remember" the value...

 

First of all you need to get the users setting and since this is stored in a database you need to run a query to find out whether the user has selected  NO or YES. Then you have to tell your function to add the html attribute SELECTED to the option which the user has chosen.

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.