Solved

CakePhp Submit extra Values

Posted on 2010-09-01
4
411 Views
Last Modified: 2013-11-10
Hi all,
I have a form in a view and I also have some variables which I need to submit.

My view looks like this:

<?php
echo $form->create('Upload',array('type'=>'file', 'url' => 'uploads'));
echo $form->input('0.file',array('type'=>'file','label'=>'Image Upload: '));
echo $form->end('Submit');
?>

The above works fine and submits to table but the table has other fields too so I'd like to submit them too.

For example - something like this:

echo $form->input('Upload', array('user_id' => '100'));

The table has also a field called user_id and I'd like to add this.

How can I do this please?

I know the format is not:

echo $form->input('Upload', array('user_id' => '37'));

What would it be ... if possible please?

thanks



0
Comment
Question by:error77
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:cwiedmann
ID: 33581692
I think you're looking for $form->hidden().  See http://book.cakephp.org/view/723/hidden

I think $form->hidden('user_id') should do the right thing as long as your model is set up correctly.
0
 

Author Comment

by:error77
ID: 33581752
I agree with you but there's a small issue here.
I have the user_id in a variable and need to add it to the form as a value.

If I used $form->hidden('user_id') .. the added user_id on the left would be null as it's not been assigned yet.

Know what I mean?
0
 
LVL 5

Accepted Solution

by:
cwiedmann earned 500 total points
ID: 33581802
In that case you could do $form->hidden('user_id', array('value'=>'37'));

Of course you can substitute a view variable for the '37' as needed.
0
 

Author Closing Comment

by:error77
ID: 33581859
Perfect! Thanks very much :o)
 
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question