Welcome Guest, Not a member yet? Register   Sign In
Using form helper? Is there a way to modify the DOM?

(This post was last modified: 09-21-2020, 11:24 AM by richb201.)

I have a form that I created. It is called http://localhost/index.php/FormUserBackend. Near the top I want to append  some radio buttons. So I tried this:

$str=form_checkbox( "test1", "Question1",FALSE, "class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
echo ($str);
$str=form_checkbox( "test2", "Question2",FALSE, "class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
echo ($str);
$str=form_checkbox( "test3", "Question3",FALSE, "class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
echo ($str);

Bur when I look at the output in the browser, none of these appended fields display. So I decided to look in the output window and I do see them near the top:
X-Powered-By: PHP/7.2.32

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate

Pragma: no-cache

Set-Cookie: cisession=hbmpjleolom8fuaqdnri0ch1abf0b5cf; expires=Tue, 22-Sep-2020 01:42:18 GMT; Max-Age=28800; path=/; HttpOnly

Content-type: text/html; charset=UTF-8

<input type="checkbox" name="test1" value="Question1"  class=form-checkbox id=input_4_3 name=q4_whichOf[] />

<input type="checkbox" name="test2" value="Question2"  class=form-checkbox id=input_4_3 name=q4_whichOf[] />

<input type="checkbox" name="test3" value="Question3"  class=form-checkbox id=input_4_3 name=q4_whichOf[] />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en-US"  class="supernova"><head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="alternate" type="application/json+oembed" href="https://www.jotform.com/oembed/?format=json&amp;url=https%3A%2F%2Fform.jotform.com%2F202597294899073" title="oEmbed Form">
<link rel="alternate" type="text/xml+oembed" href="https://www.jotform.com/oembed/?format=xml&a


They are in the wrong place. Is there some built in tools in CI to manipulate the DOM? This might be better than blindly prepending some checkboxes. 
proof that an old dog can learn new tricks

Hello, as an option for positioning, try creating a header view with the appropriate content. Connect it first, and then your form.

So I figure that I needed to modify the DOM. I found this package which will let me modify the DOM from PHP: PHP Simple HTML DOM Parser. The question is when do I do this? I can load the entire view file into a string, modify it, and then "Dump the internal DOM tree back into a string. If the $filename is set, result string will save to file". I am concerned because this is multi user system. I could surely keep the $string in a session, but how do then get load_view() to display it?
proof that an old dog can learn new tricks

the output of the form in the view at a specific place can be done like this:

PHP Code:
$form form_open('views/User_Activity_Survey.php');
$form .= form_checkbox"test1""Question1",FALSE"class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
$form .= form_checkbox"test2""Question2",FALSE"class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
$form .= form_checkbox"test3""Question3",FALSE"class=form-checkbox id=input_4_3 name=q4_whichOf[]" );
$form .= form_fieldset_close();

$this->load->view('User_Activity_Survey.php', ['form' => $form]); 

and in the place you need of User_Activity_Survey.php:
PHP Code:
<?php echo $form?>

The DOM doesn't really exist server-side, until the page is rendered in the browser it's really just a string of text. You need to render your form at the correct point of the markup, either using a variable as indicated above or by creating a view for the form and using the form helper functions directly there.

Thanks OJ. I managed to get it going using koolreport's input library.
proof that an old dog can learn new tricks

The HTML DOM (Document Object Model)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB