sfGuard ユーザー フォームに別のフォームをプルするために、embedRelation() を使用しました。現在のフォームに収まるようにスタイルを設定しようとしています。
これにより、フォームが引き込まれます。
$this->embedRelation('Profile');
しかし、削除したいいくつかの余分なhtml要素を追加しています:
<div class="form_row">
Profile
<table>
<tbody><tr>
<th><label for="sf_guard_user_Profile_department_title">Department</label></th>
<td><input type="text" name="sf_guard_user[Profile][department_title]" value="Graphic Design" id="sf_guard_user_Profile_department_title"><input type="hidden" name="sf_guard_user[Profile][id]" value="2" id="sf_guard_user_Profile_id">
<input type="hidden" name="sf_guard_user[Profile][sf_guard_user_id]" value="10" id="sf_guard_user_Profile_sf_guard_user_id"></td>
</tr>
</tbody></table> <input type="hidden" name="sf_guard_user[id]" value="10" id="sf_guard_user_id"> </div>
「プロファイル」を削除するにはどうすればよいですか? また、ラベルがテーブル ヘッダーにラップされないようにしたいと考えています。これはembedRelationを使用して可能ですか?
更新されたスキーマ フォーマッタ:
sfWidgetFormSchemaFormatter は、埋め込みフォームからテーブル要素を削除するように機能します。「プロファイル」を取り除く方法がまだわかりません。sfWidgetFormSchemaFormatter を追加しました
sfWidgetFormSchemaFormatterAc2009.class.php
<?php
class sfWidgetFormSchemaFormatterAc2009 extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = "%error% \n %label% \n %field%
%help% %hidden_fields%\n",
$errorRowFormat = "<div>%errors%</div>",
$helpFormat = '<div class="form_help">%help%</div>',
$decoratorFormat = "%content%";
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
$row = parent::formatRow(
$label,
$field,
$errors,
$help,
$hiddenFields
);
return strtr($row, array(
'%row_class%' => (count($errors) > 0) ? ' form_row_error' : '',
));
}
public function generateLabel($name, $attributes = array())
{
$labelName = $this->generateLabelName($name);
if (false === $labelName)
{
return '';
}
if (!isset($attributes['for']))
{
$attributes['for'] = $this->widgetSchema->generateId($this->widgetSchema->generateName($name));
}
// widget name are usually in lower case. Only embed form have the first character in upper case
var_dump($name);
if (preg_match('/^[A-Z]/', $name))
{
// do not display label
return ;
}
else
{
return $this->widgetSchema->renderContentTag('label', $labelName, $attributes);
}
}
}
html:
<div class="form_row">
Profile
<div>
<label for="sf_guard_user_Profile_department_title">Department</label>
<input class=" text size-300" type="text" name="sf_guard_user[Profile][department_title]" value="Graphic Design" id="sf_guard_user_Profile_department_title">
<input type="hidden" name="sf_guard_user[Profile][id]" value="2" id="sf_guard_user_Profile_id">
</div> <input type="hidden" name="sf_guard_user[id]" value="10" id="sf_guard_user_id"> </div>
更新 2:
新しい関数 generateLabel($name, $attributes = array()) は、フォームの上部にこれを生成しています:
string(16) "部門名"
プロフィールが残っています。
解決済み
JQueryを使用してこれを達成できました
これを editSuccess.php テンプレートに追加しました:
<script>
var $body = $('.content-box');
var html = $body.html();
var newHtml = html.replace('Profile', '');
$body.html(newHtml);
</script>