Carlos Garcia
Carlos Garcia

Reputation: 359

cakephp link outside form which access form input values

I have this form with a date input.

echo $this->Form->create('Nodata');
echo $this->Form->input('date1', array('type' => 'date', 'label' => 'From:'));
echo $this->Form->input('date2', array('type' => 'date', 'label' => 'To:'));
echo $this->Form->end('Get Hours');

When the form is submitted, I'm showing the results in the same view, below the form.

My problem is I have a link that is not part of the form and need to read the value (in the view) from the date field on the form to use it as a param on this link.

// date1 is the param I need to take the value from date input
<th> <?php echo $this->Html->link(__('Agents Detail'), array('controller' => 'qcas', 'action' => 'hours', 'paramProject' => $hour['Qca']['dir_id'], 'date1' => $this->data)); ?> </th>

Note this link is outside the form and I need a way to read a input on the form to use as param in my link.

Upvotes: 0

Views: 508

Answers (1)

Hoff
Hoff

Reputation: 1772

Instead of just using $this->data for your date1 element, you need to refer the field in the $this->data object.

CakePHP < 2.0

'date1' => $this->data['Nodata']['date1']

CakePHP 2.0+

'date1' => $this->request->data['Nodata']['date1']

I'm not sure what you're trying to do at the destination link, but you may need to format the date as well:

'date1' => date('Y-m-d', $this->request->data['Nodata']['date1']) // you may need strtotime

Upvotes: 1

Related Questions