Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CakePHP 2.0  Saving form data help

Posted on 2012-04-01
1
Medium Priority
?
1,113 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
1 Comment
 
LVL 13

Accepted Solution

by:
darren-w- earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

971 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