/** * Returns an entire form with input tags and everything for a specified Active Record object. Example * (post is a new record that has a title using VARCHAR and a body using TEXT): * $active_record_helper->form('post'); => * <form action='/post/create' method='post'> * <p> * <label for="post_title">Title</label><br /> * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> * </p> * <p> * <label for="post_body">Body</label><br /> * <textarea cols="40" id="post_body" name="post[body]" rows="20"> * Back to the hill and over it again! * </textarea> * </p> * <input type='submit' value='Create' /> * </form> * * It's possible to specialize the form builder by using a different action name and by supplying another * block renderer that will be evaled by PHP. * Example (entry is a new record that has a message attribute using VARCHAR): * * $active_record_helper->form('entry', array('action'=>'sign','input_block' => * '<p><?=AkInflector::humanize($column)?>: <?=$this->input($record_name, $column)?></p><br />' * ); * * <form action='/post/sign' method='post'> * Message: * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> * <input type='submit' value='Sign' /> * </form> */ public function form($record_name, $options = array()) { $record = $this->_controller->{$record_name}; $options['action'] = !empty($options['action']) ? $options['action'] : ($record->isNewRecord() ? 'create' : 'update'); $action = $this->_controller->urlFor(array('action' => $options['action'], 'id' => $record->getId())); $submit_value = !empty($options['submit_value']) ? $options['submit_value'] : strtoupper(preg_replace('/[^\\w]/', '', $options['action'])); $contents = ''; $contents .= $record->isNewRecord() ? '' : $this->_controller->ak_form_helper->hidden_field($record_name, 'id'); $contents .= $this->all_input_tags($record, $record_name, $options); $contents .= AkFormTagHelper::submit_tag($this->t($submit_value)); return AkTagHelper::content_tag('form', $contents, array('action' => $action, 'method' => 'post', 'enctype' => !empty($options['multipart']) ? 'multipart/form-data' : null)); }
public function to_label_tag($text = null, $options = array()) { $tag_value = Ak::deleteAndGetValue($options, 'value'); $name_and_id = $options; $this->add_default_name_and_id_for_value($tag_value, $name_and_id); Ak::deleteAndGetValue($options, 'index'); $options['for'] = !empty($options['for']) ? $options['for'] : @$name_and_id['id']; return AkFormTagHelper::label_tag(@$name_and_id['id'], $text, $options); }