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

(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:

form_open('views/User_Activity_Survey.php');
$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);
form_fieldset_close();
$this->load->view('User_Activity_Survey.php');


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

etc.

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
Reply
#2

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

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
Reply
#4

Hi,
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?>
Reply
#5

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.
Reply
#6

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

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

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB