Custom List Template

teoyh

Member
Hi I can some one advise me the following ;

If I am using a custom list template for a list. On top of the list i had added some input field and a submit button.

What i want to achieve is when the user fill in data in the input fields and click Add it will add the record to the list.
I am using this code from google search which i copy and paste it into my list template. I make a copy of the default list template and rename it to MyCustomTemplate. When i then add this code into the default.php
<Form Name ="form1" Method ="POST" ACTION = "AddRecord.php">
<INPUT TYPE = "Submit" Name = "Add" VALUE = "Add">

The button is generated but i do not know where to put the AddRecord.php which when i click on the button it will call the AddRecord.php.

Thank you
 
Any special reason for not using the ADD button?
If you want the form for creating a new record directly shown above the list you can include it in the list intro
{fabrik view=form id=your-form-id}
 
I wanted to customise the look and field also when I do the method which you recommend the group function does not operate properly.
 
I'm tempted to say that if you don't know how to do this, you probably shouldn't be doing it - there's a lot of ways you can mess things up.

However .. the action URL of a form is just like any URL, if it doesn't start with a / it's relative to the "base href" of the current page, which is typically the joomla root. If you're not sure, then make it absolute by giving it the full path starting with a /.

-- hugh
 
Thank you for your reply;
I tried your suggestion and do the following. I added the file (AddNew.php) in the root directory
<form method="post" action="/.AddNew.php">
<input name="go" type="submit" value="Add New" />

When I click on the button now in the debug it show it failed to open the link something like that. Thanks for your patience
 
Even if I change it to

<form method="post" action="/AddNew.php">

It still not running the file AddNew.php. I add a var_dump("test"); to check but its not showing
 
Have a look at the network tab in dev tools, see what URL it is posting to.

Sent from my Nexus 7 using Tapatalk
 
I gather from the network tab it return the following;
Key Value
Request POST /index.php?option=com_fabrik&view=list&listid=44&Itemid=467&resetfilters=0&clearordering=0&clearfilters=0 HTTP/1.1
 
In your template, did you put your code before or after this line ...

Code:
<form class="fabrikForm form-search" action="<?php echo $this->table->action;?>" method="post" id="<?php echo $this->formid;?>" name="fabrikList">

... in the default.php?

Sounds like you may have put it after, which won't work, as you can't embed a form inside a form. So your submit button would submit the list's form, not yours.

-- hugh
 
Hugh ;

thank you so much for your help, I got it finally. after reading what you write I come to understand what you mean and I change the following and it is able to run the php script AddNew.php
<form class="fabrikForm form-search" action="/AddNew.php" method="post" id="<?php echo $this->formid;?>" name="fabrikList">

I tried using your suggestion {fabrik view=form id=your-form-id} but somehow it did not work properly I have no idea why. I therefore have to resort to using the custom template. As I need to show the list below and form above.
 
In my php file I have the following code;
But I get the following error message when the AddNew.php is called, it say Class 'FabrikWorker' not found. My guess is as I am excuting the php outside Fabrik joomla does not recognised the FabrikWorker. Is there a way to declare the class or include the fabrik framework inside the php.


<?php
$db = FabrikWorker::getDbo(false, 3);
$db->setQuery("SELECT service_date FROM bus_service_date");
$results = $db->loadObjectList();
var_dump($results);
exit;

?>
 
Ah, so this is a completely standalone file. In which case you'll either have to set up the J! framework yourself, or just use native php.

Or you could use the "user ajax" file we provide, even though you aren't using ajax, you can still use the URL described in the example file (in the Fabrik front end component folder) as your post action.

Hugh




Sent from my Nexus 7 using Tapatalk
 
Sorry was busy the last few days.

After reading your explanation I make the following changes ;
<form class="fabrikForm form-search" action="index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=AddRecord" method="post" id="<?php echo $this->formid;?>" name="fabrikList">

In my user_ajax.php;

I added the following function, this is just to see if I get the value back on the screen. But seem that nothing happen.
function AddRecord(){
$db = FabrikWorker::getDbo(false, 3);
$user =& JFactory::getUser();
$regby=$user->get('username');
echo $regby;
}

I check the network tab it did show the following ;
Request POST /index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=AddRecord

Can advice which part I done wrong.

Thank you so much
 
I can't really go any further with this in Standard support, it's now in "custom code" territory. I can either do it for you on an hourly basis, or provide more in depth help in Pro.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top