All in one page instead of separate pages.

176 views
Skip to first unread message

rlweb

unread,
Jan 21, 2013, 5:06:06 PM1/21/13
to php-form-bu...@googlegroups.com
Bad title, I know.

At the moment I find I have to make separate files for the form and one for saving e.g. to DB.

So for example this would be useful:

<?php
if(!Form::isValid("selection-new") or $Form::FirstView()) {
$form = new Form("selection-new-row");
$form->configure(array(
   "prevent" => array("bootstrap", "jQuery"),
   "action" => "products-selections-new-row-save.php"
));
$form->addElement(new Element\HTML('<legend>New Selection Row</legend>'));
$form->addElement(new Element\Hidden("form", "validation"));
$form->addElement(new Element\Hidden("SelectionID", $selectionID));
$form->addElement(new Element\Textbox("Selection Name:", "SelectionName", array("required" => 1)));
$form->addElement(new Element\Textbox("Price:", "SelectionPrice"));
$form->addElement(new Element\Button);
$form->render();
}else{
$insertarray = array(
'TaID'=>$taID,
'SelectionID'=>$_POST['SelectionID'],
'SelectionName'=>$_POST['SelectionName'],
'SelectionPrice'=>$_POST['SelectionPrice']
);
$db->insert('TaPSelectionItem',$insertarray);
?>
<div class="alert alert-success">
  <h4>New Selection Row Saved!</h4>All details have been inserted successfully.<br>
</div>
<?
}
?>

rlweb

unread,
Jan 21, 2013, 5:07:22 PM1/21/13
to php-form-bu...@googlegroups.com
Quick edit bad example: 

<?php
if(Form::isValid("selection-new")) {
$insertarray = array(
'TaID'=>$taID,
'SelectionID'=>$_POST['SelectionID'],
'SelectionName'=>$_POST['SelectionName'],
'SelectionPrice'=>$_POST['SelectionPrice']
);
$db->insert('TaPSelectionItem',$insertarray);
?>
<div class="alert alert-success">
 <h4>New Selection Row Saved!</h4>All details have been inserted successfully.<br>
</div>
<?
}else{

$form = new Form("selection-new");
$form->configure();
$form->addElement(new Element\HTML('<legend>New Selection Row</legend>'));
$form->addElement(new Element\Hidden("form", "validation"));
$form->addElement(new Element\Hidden("SelectionID", $selectionID));
$form->addElement(new Element\Textbox("Selection Name:", "SelectionName", array("required" => 1)));
$form->addElement(new Element\Textbox("Price:", "SelectionPrice"));
$form->addElement(new Element\Button);
$form->render();
}
?>
Reply all
Reply to author
Forward
0 new messages