Solved

CakePhp Submit extra Values

Posted on 2010-09-01
4
402 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now