hi, i have a problem when i'm trying to save data. I am creating new
fields to my database table as the user want to, but when trying to
save it does not include the values for the new fields in the insert
query, here's my code
my view:
<div class="proveedores form">
<?php echo $this->Form->create('Proveedore',array('action' =>
'add1'));?>
        <fieldset>
                <legend><?php __('Add Proveedore'); ?></legend>
        <?php
                for($i=0; $i<sizeof($campos);$i++){
                        echo $this->Form->input($campos[$i]);
                }
        ?>
        </fieldset>
<?php echo "Para crear un nuevo campo de click en el siguiene boton:
<br />";?>
<span id="fooBar" class="FormularioArchivosEntrada">&nbsp;</span>
<input type="button" value="Crear Campo" onclick="addCampoNuevo()"/>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
        <h3><?php __('Actions'); ?></h3>
        <ul>

                <li><?php echo $this->Html->link(__('List Proveedores', true),
array('action' => 'index'));?></li>
                <li><?php echo $this->Html->link(__('List Archivos Sistemas', 
true),
array('controller' => 'archivos_sistemas', 'action' => 'index')); ?> </
li>
                <li><?php echo $this->Html->link(__('New Archivos Sistema', 
true),
array('controller' => 'archivos_sistemas', 'action' => 'add')); ?> </
li>
        </ul>
</div>

<script language="javascript">
        function addCampoNuevo(){
                nombre=prompt ("Ingrese el nombre del nuevo campo que desea 
crear:
")

                if (nombre!=""){

                        if(confirm("Esta seguro que desea crear este campo?\n 
Nombre del
Campo: "+nombre)){

                                var ni = document.getElementById("fooBar");

                                var newdiv = document.createElement('p');

                                newdiv.setAttribute('class',"nuevoDiv");

                                newdiv.innerHTML = 'Nombre del Campo';

                                ni.appendChild(newdiv);



                                //Create an input type dynamically.
                                var element = document.createElement("input");
                                //Assign different attributes to the element.
                                element.setAttribute("name", "camposNuevo[]");
                                element.setAttribute("type", 'text');
                                element.setAttribute("maxlength",'250');
                                element.setAttribute("readonly","readonly");
                                element.setAttribute("value",nombre);

                                var foo = document.getElementById("fooBar");
                                //Append the element in page (in span).
                                foo.appendChild(element);


                                //Create an input type dynamically.
                                var element1 = document.createElement("input");
                                //Assign different attributes to the element.
                                element1.setAttribute("name", "camposValor[]");
                                element1.setAttribute("type", 'text');

                                var foo = document.getElementById("fooBar");
                                //Append the element in page (in span).
                                foo.appendChild(element1);
                                document.forms[0].nombreNuevoCampo.value="";
                        }
                }
        }
</script>

as you can see i have a javascript to create new fields, and then i
make a get post in controller as follows:

function add1(){
                $id=$this->RandomString(8);//id aleatoria para crear la copia
                $resp=true;
                while($resp){
                        $resp=$this->Proveedore->comprobarID($id);
                        $id=$this->RandomString(8);
                }
                $this->data['Proveedore']['id']=$id;
                $nuevosCampos = $_POST['camposNuevo'];
                $nuevosValores = $_POST['camposValor'];
                $this->Proveedore->NuevosCampos($nuevosCampos);
                for($i=0; $i<sizeof($nuevosCampos);$i++){
                        
$this->data['Proveedore'][$nuevosCampos[$i]]=$nuevosValores[$i];
                        $this->data['Proveedore']['CampoG']="CampoG";
                }
                echo "Esta es la informacion que sube <br />";
                print_r($this->data);



                if($this->Proveedore->save($this->data)){
                        //$this->Proveedore->save($this->data);
                        //$this->Session->setFlash(__('The proveedore has been 
saved',
true));
                        //$this->redirect(array('action' => 'index'));
                }else{
                        //$this->Session->setFlash(__('The proveedore could not 
be saved.
Please, try again.', true));
                        //$this->redirect(array('action' => 'add'));
                }

        }
in my model i have this function to create new fields to my models
table:
function NuevosCampos($nuevosCampos){
                for($i=0; $i<sizeof($nuevosCampos); $i++){
                        $resp=$this->query("ALTER TABLE `proveedores` ADD `".
$nuevosCampos[$i] ."` VARCHAR(255);");
                }
        }

the new fields are created, but the values that should be safe in the
new fields won't be save, and i add them to $this->data, am i doing
something wrong?:

here's what $this->data has when before $this->Proveedore->save($this-
>data):
Array ( [Proveedore] => Array ( [name] => nombre [Nit] => nit [nuevo
campo] => nuevo campo ) )

"nuevo campo" is the new field i created, and it has a value that
should be safe in the database, but the query made by cake don't add
this new information:

INSERT INTO `proveedores` (`name`, `Nit`, `id`, `modified`, `created`)
VALUES ('nombre', 'nit, 'EJMT8qWm', '2011-10-08 15:59:18', '2011-10-08
15:59:18')

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to