Solved

CakePHP 2.0  Saving form data help

Posted on 2012-04-01
1
1,101 Views
Last Modified: 2012-06-21
Hi,  Just in the beginning stages of learning CakePHP, and would like help with saving data from a form to the database.  Basically i have about twenty forms which all are very similar, so solving this would also help me with the other forms.

What code do i put in my Models Views and Controllers, what files to create.

I have a Name texfield and Notes textarea  and a save button.

Entering a Name, and some Notes and clicking save, i want to save to a database table called Risks.

The Risks table is
-----------------------
id - INT
name - VARCHAR (255)
notes - VARCHAR (255)
created_at - DATETIME
updated_at - DATETIME

The form i have has this markup :
<form class="new-risk">
  <fieldset>
    
    <div class="control-group">
      <label class="control-label" for="input01">Name</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="input01">
      </div><!-- End Controls -->
    </div><!-- End Control Group -->
  	
  	<div class="control-group">
      <label class="control-label" for="textarea">Notes</label>
        <div class="controls">
          <textarea class="input-xlarge" id="textarea" rows="3"></textarea>
       	</div><!-- End Controls -->
   	</div><!-- End control-group -->
  
  	<div class="form-actions">
    	<button type="submit" class="btn btn-primary">Save</button>
    </div><!-- End form-actions -->
  
  
  </fieldset>
</form>

Open in new window


Solving this, would then help me with all my other forms.
0
Comment
Question by:Jon Imms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
darren-w- earned 500 total points
ID: 37795856
Hi,

assuming you have looked at this page: http://book.cakephp.org/2.0/en/models/saving-your-data.html

and this for creating the form:

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

so in your case your form needs to return an array like:

Array
(
    [ModelName] => Array  (your model name here)
    (
        [id]=>'a id'
        [name] => 'value'
        [notes] => 'value'
    )
)

Open in new window


cake will deal with the updated and created fields for you, in 2.x you dont need a model unless you have any special requirements.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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.

729 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