i have a series problem here
i'm using CakePHP 1.2.6 and 1.3 RC3
here is my DB Schema for a Job Board Plugin
Jobs has many attachments
so in jobs/admin_add.ctp (view)
i cerated a JQuery function to append a table to have multiple
attachments to be added while saving a job
so the problem is if i created the form fields on the fly and i hit
submit i get a 404 page, but if the form fields are existed using PHP
code it save them with no error!
e.g.
<?php echo $javascript->link('/job_board/js/job_board_admin.js'); ?>
<h2><?php __d('job_board','Job Board');?> :: <?php
__d('job_board','Add Job');?></h2>
<div class="jobs form">
<?php echo $form->create('Job',array('type'=>'file'));?>
<fieldset>
<div id="tabs">
<ul id="nav">
<li><a href="#info">Job Info.</a></li>
<li><a href="#details">Job Details</a></li>
<li><a href="#locations">Locations</a></li>
<li><a href="#attachments">Attachments</a></li>
</ul>
<div class="panes">
<div class="page" id="info">
<?php
echo $form->input('job_category_id');
echo $form->input('title');
echo $form->input('summery');
echo $fck->load('summery',array('height'=>300));
echo $form->input('expire');
?>
</div><!-- page -->
<div class="page" id="details">
<?php
echo $form->input('details');
echo $fck->load('details',array('height'=>500));
?>
</div> <!-- page -->
<div class="page" id="locations">
<?php
echo $form->input('Location');
?>
</div> <!-- page -->
<div class="page" id="attachments">
<?php echo $html->link(__d('job_board','Add Attachment', true),
'javascript:void(0)',array('onclick'=>'add_row()')); ?>
<table id="job_attachments">
<tr>
<th class="left meduim">Title</th>
<th class="left meduim">File</th>
<th class="">Actions</th>
</tr>
</table>
</div> <!-- page -->
</div> <!-- pans -->
</div> <!-- tabs -->
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__d('job_board','List Jobs', true),
array('action' => 'index'));?></li>
</ul>
</div>
---------------------------------------------
JQuery Function
function add_row(){
$row_id=$j("table#job_attachments tr").length;
$row='<tr id="attachment_'+$row_id+'">';
$row+='<td><input type="text" id="JobAttachment'+$row_id+'Title"
value="" maxlength="255" name="data[JobAttachment]['+$row_id+']
[title]" /></td>';
$row+='<td><input type="file" id="JobAttachment'+$row_id+'File"
value="" name="data[JobAttachment]['+$row_id+'][file]"/></td>';
$row+='<td class="actions"><a onclick="delete_row('+$row_id+')"
href="javascript:void(0)">Delete</a></td>';
$row+='</tr>';
$j("table#job_attachments").append($row);
}
function delete_row($row_id){
$j("tr#attachment_"+$row_id).remove()
}
my controller code
<?php
class JobsController extends JobBoardAppController {
var $name = 'Jobs';
var $helpers = array('Html', 'Form');
function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow('*');
}
function index() {
$this->Job->recursive = 0;
$this->set('jobs', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->setMessage('sucess',__d('job_board','Invalid Job', true));
$this->redirect(array('action' => 'index'));
}
$this->set('job', $this->Job->read(null, $id));
}
function admin_index() {
$this->Job->recursive = 0;
$this->set('jobs', $this->paginate());
}
function admin_view($id = null) {
if (!$id) {
$this->setMessage('sucess',__d('job_board','Invalid Job', true));
$this->redirect(array('action' => 'index'));
}
$this->set('job', $this->Job->read(null, $id));
}
function admin_add() {
if (!empty($this->data)) {
/*if(count($this->data['JobAttachment']) > 0 ){
$i=0;
foreach($this->data['JobAttachment'] as $attachment){
if($attachment['file']['error'] == 0){
$file_name=time().$attachment['file']['name'];
if(move_uploaded_file($attachment['file']
['tmp_name'],IMAGES."job_attachments".DS.$file_name)){
$this->data['JobAttachment'][$i]['file']=$file_name;
}else{
$this->setMessage('error',__d('job_board','Image Couldn\'t be
saved. Please try again.',true));
return null;
}
}else{
unset($this->data['JobAttachment'][$i]);
}
$i++;
}
}
$this->Job->create();
if($this->Job->saveAll($this->data,array('validate' => 'first'))){
$this->setMessage('sucess',__d('job_board','The Job has been
saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->setMessage('sucess',__d('job_board','The Job could not be
saved. Please, try again.', true));
}*/
}
$locations = $this->Job->Location->find('list');
$jobCategories = $this->Job->JobCategory->find('list');
$this->set(compact('locations', 'jobCategories'));
}
function admin_edit($id = null) {
if (!$id && empty($this->data)) {
$this->setMessage('sucess',__d('job_board','Invalid Job', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Job->save($this->data)) {
$this->setMessage('sucess',__d('job_board','The Job has been
saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->setMessage('sucess',__d('job_board','The Job could not be
saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Job->read(null, $id);
}
$locations = $this->Job->Location->find('list');
$jobCategories = $this->Job->JobCategory->find('list');
$this->set(compact('locations','jobCategories'));
}
function admin_delete($id = null) {
if (!$id) {
$this->setMessage('sucess',__d('job_board','Invalid id for Job',
true));
$this->redirect(array('action' => 'index'));
}
if ($this->Job->del($id)) {
$this->setMessage('sucess',__d('job_board','Job deleted', true));
$this->redirect(array('action' => 'index'));
}
$this->setMessage('sucess',__d('job_board','The Job could not be
deleted. Please, try again.', true));
$this->redirect(array('action' => 'index'));
}
}
?>
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
To unsubscribe, reply using "remove me" as the subject.
No comments:
Post a Comment