0
我在我的php模板中有多種形式,我想給他們不同的ID,所以他們可以使用js submited。我怎麼能這樣做,因爲我無法找到任何PHP模板?如何使用php模板更改symfony2中的表單id屬性?
這是JS的onclick所示的編輯形式:
function qytetShowEditForm(idNumber, cityName)
{
//check if there's another edit form active
if(document.getElementById("qytete_table").edit)
return;
<?php $string = $view['form']->start($edit_form).
"<td style=\"text-align: center;\"></td><td style=\"text-align: center;\">".
$view['form']->widget($edit_form['emri']).
"</td>
<td style=\"max-width: 150px; text-align: center;\">".
$view['form']->widget($edit_form['foto']).
"</td>
<td style=\"text-align: center;\">
<a onclick=\"qytetEditSubmit();\" id=\"ndrysho\" style=\"cursor: pointer; padding: 7px 12px 7px 12px; border-radius: 4px; color: white; background-color: orange;\">Ndrysho</a>
</td>".
$view['form']->end($edit_form);
$string = str_replace(array("\r\n", "\r", "\n"), "", $string);
?>
document.getElementById("row_"+idNumber).innerHTML = '<?php print($string);?>';
var edit_emri = document.getElementsByClassName('cl_emri_edit');
edit_emri[0].placeholder = cityName;
document.getElementById("qytete_table").edit = true;
}
,這是始終顯示的附加形式:
public function showAction()
{
//get all from db
$em = $this->getDoctrine()->getManager();
$qytete = $em->getRepository('EraRestoranteBundle:Qytet')->findAllOrderedByName();
$qytet = new Qytet();
//create add form
$add_form = $this->createFormBuilder($qytet)
->setAction($this->generateUrl('admin_initconfig_qytet_create'))
->setMethod('POST')
->add('emri', 'text', array('attr' => array('class' => '', 'size' => '12')))
->add('foto', 'file', array('required' => false, 'attr' => array('class' => '', 'style' => 'max-width: 150px;')))
->add('shto', 'submit', array('attr' => array('class' => '', 'style' => 'padding: 7px 20px 7px 20px; border: none; border-radius: 4px; color: white; background-color: rgb(197, 213, 43);')))
->getForm();
//create edit form
$edit_form = $this->createFormBuilder($qytet)
->setAction($this->generateUrl('admin_initconfig_qytet_update'))
->setMethod('POST')
->add('emri', 'text', array('attr' => array('class' => 'cl_emri_edit', 'size' => '12')))
->add('foto', 'file', array('required' => false, 'attr' => array('class' => 'cl_foto_edit', 'style' => 'max-width: 150px;')))
->getForm();
//render template
return $this->render('EraAdminBundle:InitConfig:qytet.html.php', array('qytete'=>$qytete, 'add_form'=>$add_form->createView(), 'edit_form'=>$edit_form->createView()));
}
在我的模板
:
在我的控制器<?php echo $view['form']->start($add_form) ?>
<td></td>
<td style="text-align: center;">
<?php echo $view['form']->widget($add_form['emri']) ?>
</td>
<td style="max-width: 150px; text-align: center;">
<?php echo $view['form']->widget($add_form['foto']) ?>
</td>
<td style="text-align: center;">
<?php echo $view['form']->widget($add_form['shto']) ?>
</td>
<?php echo $view['form']->end($add_form); ?>
我希望能夠與JS提交編輯表單是這樣的:
function qytetEditSubmit()
{
var submit = confirm("Doni t'i ruani ndryshimet?");
if(submit)
{
//document.getElementById().submit();
}
else
window.location.assign("<?php echo $view['router']->generate('admin_initconfig');?>");
}
這將是有益的,如果你可以發佈相關代碼 – srquinn
我編輯的問題... – user3080603