Issue with $this->form->create_button

edited October 2011 in Bug Reports
I'm trying to add a button to a form using the form builder class and i'm getting the error
Fatal error: Call to undefined method Form_builder::create_button()

I'm trying to add this button in my controller and i'm already loading the form_builder class because the form builds fine when I take out these two lines.

$params = array('value' => 'Next', 'use_input' => FALSE, 'id' => 'next'); $this->form_builder->create_button($params);

Comments

  • edited 7:20AM
    Do you see the create_button method around line 1029 in that file? The create_button method was added a bit ago, but it's possible that if you have an older version of FUEL it may not be in there.
  • edited 7:20AM
    Yep I don't have that method in the form_builder library. I updated my form_builder library with the latest version, and now the page actually shows stuff, but it's giving an error that says

    A PHP Error was encountered Severity: Notice Message: Undefined index: next Filename: compiled/daa8ff4e32a6323524e97b25da079e3d.d17.php Line Number: 149

    Here's the code I have in my controller. I can set the button to a variable and then access it in the view just fine, but if I do it that way, it's outside of the div tags and I want it inside the div tags.
    // build the form $fields = array(); $fields['name'] = array('label' => 'Contact Name', 'required' => TRUE, 'class' => 'input left'); $fields['company'] = array('label' => 'Company', 'required' => TRUE, 'class' => 'input left'); $fields['address'] = array('label' => 'Address', 'required' => TRUE, 'class' => 'input left'); $fields['phone'] = array('label' => 'Phone', 'required' => FALSE, 'class' => 'input left'); $fields['fax'] = array('label' => 'FAX', 'required' => FALSE, 'class' => 'input left'); $fields['email'] = array('label' => 'Email', 'required' => TRUE, 'class' => 'input left'); // add the next button $params = array('value' => 'Next', 'use_input' => FALSE); $fields['next'] = $this->form_builder->create_button($params); $fields2['inspection'] = array('label' => 'Inspection and Estimate Required by When?', 'required' => TRUE, 'class' => 'input left'); $fields2['location'] = array('label' => 'Name of Location', 'required' => TRUE, 'class' => 'input left'); $fields2['address'] = array('label' => 'Address', 'required' => TRUE, 'class' => 'input left'); $fields2['contactName'] = array('label' => 'Contact Name', 'required' => TRUE, 'class' => 'input left'); $fields2['phoneNum'] = array('label' => 'Phone Number', 'required' => FALSE, 'class' => 'input left'); $fields2['access'] = array('label' => 'Access', 'required' => TRUE, 'class' => 'input left'); $fields2['reason'] = array('label' => 'Reason for Estimate', 'required' => TRUE, 'class' => 'input left'); $fields2['comments'] = array('label' => 'Comments', 'required' => TRUE, 'class' => 'input left'); $this->form_builder->use_form_tag = FALSE; // will set the values of the fields if there is an error... must be after set_fields $this->form_builder->set_validator($this->validator); $this->form_builder->set_field_values($_POST); $this->form_builder->set_fields($fields); $vars['form1'] = $this->form_builder->render(); $this->form_builder->set_fields($fields2); $vars['form2'] = $this->form_builder->render();
  • edited 7:20AM
    That error is a Dwoo compiled error and doesn't sound like an issue with the code you have above. Does it still appear if you clear out the application/cache/dwoo/compiled folder?
  • edited 7:20AM
    Ok that error is gone, but the button isn't rendering correctly.

    if I go to the net console of firebug and look at the http response, here's what is actually returned to the browser. Is there a bug in the create_button function?
    <input type="text" name="next" id="next" value="&lt;button type="button" name="" id="" value="Next"&gt;Next&lt;/button&gt;" size="40" />
  • edited 7:20AM
    Hmm... Do you have the latest version of the Form.php library? I only ask because Form_builder.php uses it and it appears you had an older version of Form_builder.
  • edited 7:20AM
    I've updated the form.php library and now it prints out a label and input tag with the button html markup in the input field

    Here's the code that's returned:
    <label for="next" id="label_next">Next</label> <input type="text" name="next" id="next" value="&lt;button type=&quot;button&quot; name=&quot;&quot; id=&quot;&quot; value=&quot;Next&quot;&gt;Next&lt;/button&gt;" size="40" />
  • edited October 2011
    a
  • edited 7:20AM
    Try changing your button code to the following instead of using the method to create the button which outputs the HTML:
    $fields['next'] = array('type' => 'button', 'value' => 'Next', 'use_input' => FALSE);
  • edited 7:20AM
    Yea that code works, but it has a label tag for the button which shouldn't be there.
  • edited 7:20AM
    You are wanting this button to appear at the bottom of the first rendered form correct? If so, try using the "other_actions" property on the form_builder and put in the HTML for that button which you can use doing something like what you had above:
    $params = array('value' => 'Next', 'use_input' => FALSE); $this->form_builder->other_actions = $this->form_builder->create_button($params);
  • edited 7:20AM
    Ok so that renders the button, but it's rendered on both of the forms. What I ultimately want is a "Next" button on the first form, and a "Submit" button on the second form.
  • edited 7:20AM
    Before you render the next form, set other_actions to an empty string.
  • edited 7:20AM
    Sweet. Now how do I get rid of the submit button on the first form? I was trying the exclude parameter but couldn't get the button to disappear.
  • edited 7:20AM
    Set the "submit_value" form_builder property to an empty string.
  • edited 7:20AM
    Awesome Thanks! That was simple enough.
Sign In or Register to comment.