PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] CakePHP fetching data from form

 January 19, 2022     ajax, cakephp, javascript, jquery, php     No comments   

Issue

I am trying to get the value of input data in a cakephp form so that I can use it in a sql query to auto fill other data. Currently i'm trying to use $this->request->data but it's not showing any results when I change my customer. I want it to display the customer that is selected but currently it's just blank. Not sure if i'm trying to get the data correctly or displaying it incorrectly.

enter image description here My add.ctp

<div class="invoices form large-9 medium-8 columns content">
    <?= $this->Form->create($invoice) ?>
    <fieldset>
        <legend><?= __('Add Invoice') ?></legend>
        <?php

            echo $this->Form->input('customer_id', ['options' => $customers, 'empty' => true,'id'=>'customers']);        ?>

    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>


<script>
            document.getElementById('customers').addEventListener('change',function(){
                alert(<?php echo $this->request->data('customers');
                ?>)
                });

            </script>

Solution

Replace your code with this

document.getElementById('customers').addEventListener('change',function(){
       alert(this.value);
 });


Answered By - Subhankar Mitra
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing