?
Solved

CakePhp Submit extra Values

Posted on 2010-09-01
4
Medium Priority
?
424 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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