Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在一个新文档上使用PHP创建一个包含多个提交按钮的表单_Php - Fatal编程技术网

在一个新文档上使用PHP创建一个包含多个提交按钮的表单

在一个新文档上使用PHP创建一个包含多个提交按钮的表单,php,Php,我的DomDocument只会按下一个提交按钮。我需要所有按钮都是提交,但只有第一个按钮是提交,其余的都变成文本区域,即使我指定了“提交” 我知道我可以用HTML来做这件事,但是DomDocuments只打印出1个submit 我如何拥有超过1个提交按钮: 代码: 您可以压缩大量代码,只需使用$tSFB1->setAttribute('type','submit')等等。setAttribute()将创建一个属性,如果它不存在。感谢Dave Chen清理我的代码,现在尝试Marc B。感谢Mar

我的DomDocument只会按下一个提交按钮。我需要所有按钮都是提交,但只有第一个按钮是提交,其余的都变成文本区域,即使我指定了“提交”

我知道我可以用HTML来做这件事,但是DomDocuments只打印出1个submit

我如何拥有超过1个提交按钮:

代码:


您可以压缩大量代码,只需使用
$tSFB1->setAttribute('type','submit')
等等。setAttribute()将创建一个属性,如果它不存在。感谢Dave Chen清理我的代码,现在尝试Marc B。感谢Marc,完成了。
$tSForm = new DOMDocument;
$tSFRoot = $tSForm->createElement('Form', '');
$tSFId =  $tSForm->createAttribute('ID');
$tSFId->value = 'tSFORM';
$tSFRoot->appendChild($tSFId);
$tSFAction = $tSForm->createAttribute('Action');
$tSFAction->value = $_SERVER['PHP_SELF'];
$tSFRoot->appendChild($tSFAction);
$tSFMethod = $tSForm->createAttribute('Method');
$tSFMethod->value = 'POST';
$tSFRoot->appendChild($tSFMethod);

/// Create Button 1    
$tSFB1 = $tSForm->createElement('Input','');
$tSFB1Type = $tSForm->createAttribute('type');
$tSFB1Type->value = 'submit';
$tSFB1->appendChild($tSFB1Type);
$tSFB1Name = $tSForm->createAttribute('name');
$tSFB1Name->value = 'print';
$tSFB1->appendChild($tSFB1Name);
$tSFB1Name = $tSForm->createAttribute('value');
$tSFB1Name->value = 'PRINT';
$tSFB1->appendChild($tSFB1Name);
$tSFRoot->appendChild($tSFB1);
/// Create Button 2
$tSFB2 = $tSForm->createElement('Input','');
$tSFB2Type = $tSForm->createAttribute('type');
$tSFId->value = 'submit';
$tSFB2->appendChild($tSFB2Type);
$tSFB2Name = $tSForm->createAttribute('name');
$tSFB2Name->value = 'newTS';
$tSFB2->appendChild($tSFB2Name);
$tSFB2Name = $tSForm->createAttribute('value');
$tSFB2Name->value = 'New Time Sheet';
$tSFB2->appendChild($tSFB2Name);
$tSFRoot->appendChild($tSFB2);
/// Create Button3

$tSForm->appendChild($tSFRoot);
echo $tSForm->saveHTML();