Hello There,

My problem is:
I have declared an empty PHP array.
and onsubmit of button I want to add the _post values to array at every time on my form.
I am working this in Yii framwork.

Array declred as:

$skill_values_array=array();

button code

<?php echo CHtml::submitButton(Yii::t($model, 'next'), array('id' => 'submitbutton')); ?>

and my JS code

<?php Yii::app()->getClientScript()->registerScript('hello',
        '  $(\'#submitbutton\').click(function(){           
        // HERE I WANT TO UPDATE MY ARRAY WITH VALUES GOT THROUGH FORM
    });
    ');?>

How can I do this ?

Background

The direct relationship between php and javascript is primarily one way. PHP on the server can be built out to print out javascript. However, javascript is a client side language. Once the code reaches the client, the only way to get back to the PHP is to return to the server (via Ajax or a new Webpage request).

This means you could build up your javascript array and send it back to the server to be handled by your array. But you cannot directly set a php value from javascript.

Solution Ideas
  1. You might try using jQuery as you are already using a framework.
  2. Another approach (with the basic concept) is a php formhttp://www.w3schools.com/php/php_forms.asp
  3. It is possible to do it without jquery, but if you aren't familiar with setting up ajax, cross browser support is already baked into jQuery.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.