Custom Data Attribute not Populating Value - php

I have a simple delete function. Here is where I set the custom data:
<?php echo $this->Html->link(
__('Delete'),
'#CoursesModal',
array(
'class' => 'btn-remove-modal',
'data-toggle' => 'modal',
'role' => 'button',
'data-uid' => $course['Course']['id'],
'data-uname' => $course['Course']['name']
));
?>
It shows in the element fine:
Delete
But when it comes to deleting this object (here's the code for it:)
<?php echo $this->Html->link(__('Delete'),'/courses/delete/#{uid}',array('class' => 'btn btn-danger delete-course-link')) ?>
For some reason the {uid} doesn't translate to 5 - which causes it not to work.
What am I doing wrong?

Related

How to add icon class in PHP form_submit of Codeigniter

<?php echo form_submit(['type'=>'submit', 'class'=>'btn login-btn', 'name'=>'btnLogin', 'i class'=>'icon-long-arrow-right' , 'value'=>'Login']); ?>
How to display an icon on button in Codeigniter.I tried this but it didn't show icon on button.Where to make change so that icon will displayed on button?
$data = array(
'name' => 'button',
'id' => 'button',
'value' => 'true',
'type' => 'submit',
'class'=>'btn btn-primary btn-sm icon-cancel-circle2',
'content' => '<i class="icon-long-arrow-right"></i>'
);
echo form_button($data);
you can use this.Hope it helps.
try this
<?php echo form_submit('btnLogin', 'Login', '"class"="btn login-btn" "i class"="icon-long-arrow-right"'); ?
the first parameter is the name, second is the value of your button.

session based multistep form cakephp

Basically i have 3 forms.
I have one action in my form and i want create 3 steps form using session.
I want when i click the next button it validates the form1,if successful then redirects to form2..
like wise for form3 but keep all the data in session and in third step the action goes runs and add all the data to database.
I only need to check conditions from session before my insert goes run in my action addjob.
Plz help me to do this.
My main question is how to get all the post data in one session variable and check step by step before insert..
i am learner in cakephp and i have not enough idea about session.
if you are a expert then plz do this.
public function addjob($id = NULL) {
$this->layout = "layout_registration_old";
$this->loadcategory();
$this->loadcargo();
//$this->loadsubcategory();
$this->getCountries();
$this->getstates();
if ($this->request->is('put') || $this->request->is('post')) {
if (isset($id)) {
$this->Job->id = $id;
} else {
$this->request->data['Job']['status'] = 1;
$this->request->data['Job']['job_type'] = 1; //this is used to update the job type private or public.
$this->Job->create();
}
$this->Job->set($this->request->data);
if ($this->Job->AddEdit()) { // ADDEdit is the validation name in model
if ($this->Job->save($this->request->data['Job'], false)) {
if (isset($id)) {
$this->Session->setFlash(__('Job has been updated sucessfully.'));
} else {
$this->Session->setFlash(__('Job has been added succesfully.'));
}
$this->redirect(array('controller' => 'jobs', 'action' => 'index'));
}
} else {
$errors = $this->Job->validationErrors;
$this->Session->setFlash(__('Please check your entry.'), 'flash_error');
}
}
if (isset($id)) {
$this->request->data = $this->Job->find('first', array('conditions' => array('id' => base64_decode($id))));
}
}
form - 1
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('customer_name',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('customer_no',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('customer_email',array('div' => false, 'label' => false));?>
<?php
echo $this->Form->input('transport_type', array(
'type' => 'select',
'label' => false,
'class' => 'select',
'options' => array(
1 => 'Road'
),
));
?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
form - 2
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('fname',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('lname',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('email',array('div' => false, 'label' => false));?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
form - 3
<?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>
<?php echo $this->Form->input('shop',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('business',array('div' => false, 'label' => false));?>
<?php echo $this->Form->input('status',array('div' => false, 'label' => false));?>
<?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
Instead of saving the data from first 2 forms in a session, you should implement a multi part form using any javascript solution (Form wizard). Validate the data of each step using javascript or via ajax (if needs to be done dynamically) before moving to the next step and submit form at the end so that you don't have to play with sessions.
Example link
PS - This could go as a comment to the question but I haven't gained enough reputations to post comments yet :(

How to put glyphicon inside cakephp submit form?

The code:
<?php echo $this->Form->submit('<i class="glyphicon glyphicon-arrow-right"></i>', array('class' => array('btn btn-danger')), array('escape' => false)); ?>
Instead of glyphicon it shows just text:
<i class="glyphicon glyphicon-arrow-right"></i>
How to solve this?
As per the docs, you can't use escape with Submit- you have to use Button instead and specify that it's a submit button:
echo $this->Form->button('<i class="glyphicon glyphicon-arrow-right"></i>', array(
'type' => 'submit',
'class' => 'btn btn-danger',
'escape' => false
));
Form->submit() should take two options, a caption and an array of options. You are passing it the caption plus two arrays. Also I don't think in this case you need to wrap these options within sub-arrays.
Try this:
echo $this->Form->submit('<i class="glyphicon glyphicon-arrow-right"></i>',
array('class' => 'btn btn-danger', 'escape' => false)
);

Cakephp form has no data on submit

Using cakephp 1.3 I fill out a form, and upon debugging the submit, I notice that
data:$("#submit-478065271").closest("form").serialize()
is empty. Why would something like that happen? I've checked that the form actually has data, which I can serialize manually. Here is the submit code:
echo $this->Js->submit(
'Sign up',
array(
'class' => 'btn btn_submit fr register_submit register_btn_align',
'url' => array('controller' => 'email_guides', 'action' => 'subscribe'),
'before' => '$(".error-message").remove();' . $this->Js->get('#loading')->effect(
'fadeIn',
array('buffer' => false)
),
'complete' => $this->Js->get('#loading')->effect(
'fadeOut',
array('buffer' => false)
) . 'debugger;',
'success' => 'if(data.success) {
$("#CustomUserFirstName").val("");
$("#CustomUserEmail").val("");
$("#EmailGuidesUserStartDate").val("' . date('d/m/Y', strtotime('+1 Weekday')) . '");
$("#EmailGuidesUserTerms").attr("checked", false);
$("#signupModal").hide();
} else {
$("#signupModal").hide();
}
'type' => 'json'
)
);
?>
<?php echo $this->Form->end(); ?>
UPDATE: I've noticed that the form is not a parent of the submit element ... which is very bizarre. This would explain why .closest("form") returns an empty array.

Cakephp - Create a search field with a search button

I need an "onclick" action on the button so i get redirected for something like this:
location/[textfield_data]
http://snag.gy/wz395.jpg
I am using cakephp and at this moment the nearest i reached was this.
echo $this->Form->input('link', array('label' => false, "class" => "form-control input-medium", "placeholder" => __('Procurar')));
echo $this->Form->button('', array('class' => 'btn btn-primary icon-search icon-white' ,'onclick' => "location.href='/'"));
With my code, cakephp is retrieving me this:
/[view]?data%5Blink%5D=
The [view] is the current page i am in.
FOUND THE SOLUTION
Ive found the solution this way.
echo $this->Form->input('link', array('label' => false, "class" => " form-control input-medium", "placeholder" => __('Procurar'), 'id' => 'search'));
echo $this->Form->button(null, array('class' => 'btn btn-primary icon-search icon-white' ,'onclick' => "location.href='/mywantedurl/'+document.getElementById('search').value;"));
Note that i didnt use any form->create or form->end, otherwise it wont work.
Why do you need to use JavaScript? Just use the GET method instead. You should be using GET instead of POST requests for searches any way, so the request can be book-marked etc.
You would achieve this using $this->request->query instead of $this->request->data.
<?php
// app/View/Locations/index.ctp
echo $this->Form->create('Location', array('type' => 'get'));
echo $this->Form->input('Location.keywords');
echo $this->Form->end('Search');
And then in your corresponding controller:
<?php
// app/Controller/LocationsController.php
class LocationsController extends AppController {
public function search() {
if (!isset($this->request->query['keywords'])) {
throw new BadRequestException();
}
$results = $this->Location->findByKeywords($this->request->query['keywords']);
$this->set('results', $results);
}
}
I don’t know the actual schema of your database tables or your model names, but the above should point you in the right direction.
I use a code like this
echo $this->Form->input('link', array('label' => false, "class" => "form-control input-medium", "placeholder" => __('Procurar'), 'id' => 'search-field'));
echo $this->Form->button('', array('class' => 'btn btn-primary icon-search icon-white' , 'id' => 'search-button'));
$this->Js->get('#search-button');
$this->Js->event('click', 'edit()');
$this->Js->buffer
(
"function edit()
{
search_term = this.document.getElementById('search-field').value;
if(search_term)
window.location = \"/index.php/location/\" + search_term;
return false;
}"
);

Categories