Your add function shouldn't really need a parameter associated with
it.  Edit/View/Delete controller actions use it, but there is no id
associated with an add.  When you call add, you are calling /country/
add without a parameter, but your $region_id = null section is
defaulting it to 0.

I'm assuming you want to call /country/add/3 to make whatever country
you next add be placed in the region_id equal to 3 in the following
example.

    function add($region_id = null)
    {
       if (empty($this->data))
       {
         $this->set('region_id', $region_id);
       }
       else
        {
            if ($this->Country->save($this->data))
            {
                $this->flash('New country added.', '/countries', 2);
            }
        }
    }

You could also do the URL /counter/add?region=3 as follows...

    function add()
    {
      // On first page load, set region id if it was passed in the url
      if (empty($this->data))
         if (isset($this->params['url']['region']))
         {
            $this->data['Country']['region_id'] = $this->params['url']
['region'];
         }
      }
      else
       {
            if ($this->Country->save($this->data))
            {
                $this->flash('New country added.', '/countries', 2);
            }
        }
    }

and have your HTML tag look something like (not sure if syntax is
correct)
    echo $html->hidden('Country/region_id', array( 'value' =>
$html->tagValue('Country/region_id'));

I use the parameters as "suggestions" for what values should be
defaulted to when the page opens.  You can then still display a select
box for the region if you'd like the user to change it to something
else, or continue using the hidden value and just display the text
using the $html->tagValue().




On Apr 13, 9:41 am, "ifcanduela" <[EMAIL PROTECTED]> wrote:
> Ugh, I'm such a newbie...
>
> The view gets the value for region_id OK, but when I submit the form,
> it inserts a 0 in the region_id field of the new record instead of the
> real region_id. Am I missing something?
>
> Thanks in advance.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to