gmc1103 Posted February 5, 2015 Share Posted February 5, 2015 Hi I have this following code, i'm using easyui-datagrid and when i choose "new" it open a form you can see in the end of the code but the echo returns nothing. <?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } $userid = $fgmembersite->UserId(); ?> <body> <div class="easyui-layout"> <h2 class="sub_title">Bem vindo <?= $fgmembersite->UserFullName(); ?> !</h2> <h2>Gestão das Atividades Docentes</h2> <div class="demo-info" style="margin-bottom:10px"> <div class="demo-tip icon-tip"> </div> <div>*Clique no sinal "+" numa linha para editar o registo.</div> </div> <table id="dg" class="easyui-datagrid" url="get_atividades.php" style="width:1800px;height:500px; border:1px solid #ccc;" title="Gestão das Atividades" toolbar="#toolbar" pagination="true" idField="id" rownumbers="true" fitColumns="true" resizable="true"> <thead> <tr> <th field="idativade" width="20">Nº</th> <th field="cargo" width="200" editor="{type:'validatebox',options:{required:true}}">Cargo</th> <th field="atividade" width="200" editor="{type:'validatebox',options:{required:true}}">Atividade</th> <th field="data" width="50" editor="{type:'validatebox',options:{required:true}}">Data</th> <th field="hora" width="50" editor="{type:'validatebox',options:{validType:'hora'}}">Hora</th> <th field="local" width="100" editor="{type:'validatebox',options:{validType:'local'}}">Local</th> <th field="inter" width="200" editor="{type:'validatebox',options:{validType:'inter'}}">Intervenientes</th> <th field="notas" width="150">Notas</th> </tr> </thead> </table> <div id="toolbar"> <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="novaAtividade()">Nova</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeAtividade()">Remover</a> <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="saveAtividade()">Guardar</a> </div> </div> <div id="dlg" class="easyui-dialog" style="width:800px;height:500px;padding:10px 20px" closed="true" buttons="#dlg-buttons"> <div class="ftitle">Nova Atividade</div> <form id="fm" method="post" novalidate> <div class="fitem"> <label>Cargo:</label> <select name="cargo" id="cargo_name"></select> </div> <div class="fitem"> <label>Atividade:</label> <input name="nome" required="true" class="easyui-textbox" size="60"> </div> <div class="fitemdatahora"> <label>Data:</label> <input name="data" class="easyui-datebox" id="data" size="30"> </div> <div class="fitemdatahora"> <label>Hora:</label> <input id="hora" class="easyui-timespinner" name="hora"> </div> <div class="fitem"> <label>Local:</label> <input name="local" class="easyui-textbox" required="true"> </div> <div class="fitem"> <label>Intervenientes:</label> <input name="inter" class="easyui-textbox" required="true"> </div> <div class="fitem"> <label>Notas:</label> <input name="notas" id="notas" size="60"> </div> <div class="fitem"> <input type="text" name='iduser' id='iduser' value="<?= echo $fgmembersite->UserId(); ?>"> </div> </form> </div> <div id="dlg-buttons"> <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Registar</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancelar</a> </div> </body> </html> <input type="text" name='iduser' id='iduser' value="<?= echo $fgmembersite->UserId(); ?>"> The "echo" outside the form works, i have the userId, so what's wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/294393-help-with-echo/ Share on other sites More sharing options...
Ch0cu3r Posted February 5, 2015 Share Posted February 5, 2015 You dont need to use echo within PHP's "echo" short tags (that is what the <?= tag means). You should note however if you are not using PHP5.4 then this type of PHP tag is not available unless you enable a setting called short_open_tag. For this reason I always use full PHP tags <input type="text" name='iduser' id='iduser' value="<?php echo $fgmembersite->UserId(); ?>"> OR use the following as you have defined $userid line 9 <input type="text" name='iduser' id='iduser' value="<?php echo $userid; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/294393-help-with-echo/#findComment-1504945 Share on other sites More sharing options...
gmc1103 Posted February 5, 2015 Author Share Posted February 5, 2015 Hi Thank for your help Doesn't work This is my full php file <?PHP require_once("./include/membersite_config.php"); $userid = $fgmembersite->UserId(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="keywords" content="ebspma, atividades, registar, alterar, apagar"> <meta name="description" content="ebspma, atividades, registar, alterar, apagar"> <title>Gestão das Atividades Docentes</title> <link rel="stylesheet" type="text/css" href="css/easyui.css"> <link rel="stylesheet" type="text/css" href="css/icon.css"> <link rel="stylesheet" type="text/css" href="css/demo.css"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script> <script type="text/javascript" src="js/datagrid-filter.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script> <style type="text/css"> #fm{ margin:0; padding:20px 50px; } .ftitle{ font-size:14px; font-weight:bold; padding:10px 0; margin-bottom:10px; border-bottom:1px solid #ccc; } .fitem{ margin-bottom:15px; } .fitem label{ display:inline-block; width:120px; } .fitem input{ width:200px; } <style type="text/css"> #fm{ margin:0; padding:10px 30px; } .ftitle{ font-size:14px; font-weight:bold; padding:5px 0; margin-bottom:10px; border-bottom:1px solid #ccc; } .fitem{ margin-bottom:15px; } .fitem label{ display:inline-block; width:120px; } .fitem input{ width:200px; } .fitemdatahora{ margin-bottom:15px; } .fitemdatahora label{ display:inline-block; width:120px; } .fitemdatahora input{ width:100px; } </style> <script type="text/javascript"> $(function(){ $('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div class="ddv"></div>'; }, onExpandRow: function(index,row){ var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv'); ddv.panel({ border:false, cache:true, href:'show_form.php?index='+index, onLoad:function(){ $('#dg').datagrid('fixDetailRowHeight',index); $('#dg').datagrid('selectRow',index); $('#dg').datagrid('getRowDetail',index).find('form').form('load',row); } }); $('#dg').datagrid('fixDetailRowHeight',index); } }); }); function removeAtividade(){ var row = $('#dg').datagrid('getSelected'); if (row){ $.messager.confirm('Confirmar!!','Tem a certeza que deseja remover esta atividade?',function(r){ if (r){ var index = $('#dg').datagrid('getRowIndex',row); $.post({id:row.id},function(){ $('#dg').datagrid('deleteRow',index); }); $.post('remove_atividade.php',{id:row.idativade},function(result){ if (result.success){ $('#dg').datagrid('reload'); } else { $.messager.show({ // show error message title: 'Erro', msg: result.errorMsg }); } },'json'); } }); } } function saveAtividade(index){ var row = $('#dg').datagrid('getRows')[index]; var url = row.isNewRecord ? 'nova_atividade.php' : 'update_atividade.php?id='+row.idativade; $('#dg').datagrid('getRowDetail',index).find('form').form('submit',{ url: url, onSubmit: function(){ return $(this).form('validate'); }, success: function(data){ data = eval('('+data+')'); data.isNewRecord = false; $('#dg').datagrid('collapseRow',index); $('#dg').datagrid('updateRow',{ index: index, row: data }); } }); } function cancelItem(index){ var row = $('#dg').datagrid('getRows')[index]; if (row.isNewRecord){ $('#dg').datagrid('deleteRow',index); } else { $('#dg').datagrid('collapseRow',index); } } function novaAtividade(){ $('#dlg').dialog('open').dialog('setTitle','Registar Nova Atividade'); $('#fm').form('clear'); } function saveUser(){ $('#fm').form('submit',{ url: 'nova_atividade.php', onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ var result = eval('('+result+')'); if (result.errorMsg){ $.messager.show({ title: 'Erro', msg: result.errorMsg }); } else { $('#dlg').dialog('close'); // close the dialog $('#dg').datagrid('reload'); // reload the user data } } }); } function populateCargo() { $.getJSON('t.php', {cargo:$('#cargo').val()}, function(data) { var select = $('#cargo_name'); var options = select.prop('options'); $('option', select).remove(); $.each(data, function(index, array) { options[options.length] = new Option(array['cargo']); }); }); } $(document).ready(function() { populateCargo(); $('#cargo').change(function() { populateCargo(); }); }); </script> <script type="text/javascript"> $('#data').datebox({ formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();}, parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));} }); </script> </head> <body> <div class="easyui-layout"> <h2 class="sub_title">Bem vindo <?= $fgmembersite->UserFullName(); ?> !</h2> <h2 class="sub_title">Bem vindo <?php echo $userid; ?> !</h2> <h2>Gestão das Atividades Docentes</h2> <div class="demo-info" style="margin-bottom:10px"> <div class="demo-tip icon-tip"> </div> <div>*Clique no sinal "+" numa linha para editar o registo.</div> </div> <table id="dg" class="easyui-datagrid" url="get_atividades.php" style="width:1800px;height:500px; border:1px solid #ccc;" title="Gestão das Atividades" toolbar="#toolbar" pagination="true" idField="id" rownumbers="true" fitColumns="true" resizable="true"> <thead> <tr> <th field="idativade" width="20">Nº</th> <th field="cargo" width="200">Cargo</th> <th field="atividade" width="200">Atividade</th> <th field="data" width="50">Data</th> <th field="hora" width="50">Hora</th> <th field="local" width="100">Local</th> <th field="inter" width="200">Intervenientes</th> <th field="notas" width="150">Notas</th> </tr> </thead> </table> <div id="toolbar"> <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="novaAtividade()">Nova</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeAtividade()">Remover</a> </div> </div> <div id="dlg" class="easyui-dialog" style="width:800px;height:500px;padding:10px 20px" closed="true" buttons="#dlg-buttons"> <div class="ftitle">Nova Atividade</div> <form id="fm" method="post" novalidate> <div class="fitem"> <label>Cargo:</label> <select name="cargo" id="cargo_name"></select> </div> <div class="fitem"> <label>Atividade:</label> <input name="nome" required="true" class="easyui-textbox" size="60"> </div> <div class="fitemdatahora"> <label>Data:</label> <input name="data" class="easyui-datebox" id="data" size="30"> </div> <div class="fitemdatahora"> <label>Hora:</label> <input id="hora" class="easyui-timespinner" name="hora"> </div> <div class="fitem"> <label>Local:</label> <input name="local" class="easyui-textbox" required="true"> </div> <div class="fitem"> <label>Intervenientes:</label> <input name="inter" class="easyui-textbox" required="true"> </div> <div class="fitem"> <label>Notas:</label> <input name="notas" id="notas" size="60"> </div> <div class="fitem"> <input type="text" name='iduser' id='iduser' value="<?php echo $userid; ?>"> </div> </form> </div> <div id="dlg-buttons"> <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Registar</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancelar</a> </div> </body> </html> Outside the form i have the variable working. Inside the form....is blank I can populate the first <div class="fitem"> <label>Cargo:</label> <select name="cargo" id="cargo_name"></select> </div> with JavaScript function function populateCargo() { $.getJSON('t.php', {cargo:$('#cargo').val()}, function(data) { var select = $('#cargo_name'); var options = select.prop('options'); $('option', select).remove(); $.each(data, function(index, array) { options[options.length] = new Option(array['cargo']); }); }); } $(document).ready(function() { populateCargo(); $('#cargo').change(function() { populateCargo(); }); }); But i can't populate this one <div class="fitem"> <input type="text" name='iduser' id='iduser' value="<?php echo $userid; ?>"> </div> and i know the variable is not null...so what i'm doing wrong? Regards Quote Link to comment https://forums.phpfreaks.com/topic/294393-help-with-echo/#findComment-1504961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.