simple html post form not working

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 11:41 am

Hi folks

I started using Joomla a couple of days ago but was already familiar with HTML and PHP. I have created a simple form in my Joomla website which posts to a php file for actioning to update a Mysql database. The form itself works ok outside of Joomla but not when I use it within Joomla, I press the submit button and nothing happens, no text is echoed back to screen and no updates are made to the database, its as if it can't find the php file which processes the form.

I'm using ver 3.5.1 with the direct.php extension. PHP and Mysql are working ok as I can code these directly in the Joomla article fine, its only the form that isn't working.

Have looked already on the web but can't find an answer.

Thanks in advance for any suggestions.

Pete
Last edited by toivo on Sun Jun 12, 2016 12:27 pm, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17445
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: simple html post form not working

Post by toivo » Sun Jun 12, 2016 12:32 pm

The form itself works ok outside of Joomla but not when I use it within Joomla
If the form is a PHP script and the file to which the data is posted is also a PHP script that you wrote, how are you using the form "within Joomla"?
Toivo Talikka, Global Moderator

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 6:54 pm

Hi Toivo

The form is not a php script, it is HTML within my Joomla article. The file that the form posts to is a php script.

The following code doesn't mean much at the moment, it's just a way of getting a form to work so that once it is I can put it to proper use. Within my Joomla article the code is:-

# <form action="EvaluateForm.php" method="POST">
# <b>Name</b>
# <input type="text" size="45" name="Username"><br />
# <input type="submit" value="Submit now">
# </form>

This gets processes by the EvaluateForm.php file which echoes the username and some other text back to screen and updates a record in a database.

To test, If I create a file in my XAMPP/htdocs folder and use this code it works fine.

Snewzer

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17445
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: simple html post form not working

Post by toivo » Sun Jun 12, 2016 7:59 pm

Does your script EvaluateForm.php bootstrap the Joomla CLI so that the methods of the Joomla API are available or are you somehow using some component?
Toivo Talikka, Global Moderator

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 8:22 pm

I should mention that although familiar with PHP and HTML I consider myself a newbie. Self taught, and I haven't done a jot of coding in the last 4 years. Sorry but I'm afraid I don't really understand what your question is asking.

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: simple html post form not working

Post by sozzled » Sun Jun 12, 2016 9:33 pm

What I suspect we're trying to understand here is how you've gone about inserting your PHP code into Joomla. As with most CMS products, injecting PHP into Joomla is not done merely by adding a few lines into a "article", for example, but it's done via what we call Joomla extensions (e.g. components, modules and plugins). Perhaps the "simplest" way of having a site visitor interact with the site database—from a Joomla perspective, at least—is via a module. That's not the only way, but it's one that I'm certainly familiar with. I'm guessing here, however, because I don't know how your EvaluateForm.php tool utilises the Joomla API (or whether it interacts with it in the way you want it to).

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30940
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: simple html post form not working

Post by Per Yngve Berg » Sun Jun 12, 2016 9:42 pm

In Joomla all posts have to go through index.php.

You will be easier to use a forms extension or a cck.

http://extensions.joomla.org/category/c ... back/forms
http://extensions.joomla.org/category/a ... nstruction

I use Fabrik myself.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 9:48 pm

Thanks...That I do understand, and it's via the 'direct.php' extension which I have installed. PHP itself works fine, I can write php code directly into the article and it works fine. it's only when I try to use this form that it isn't working.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 9:49 pm

[quote="Per Yngve Berg"]In Joomla all posts have to go through index.php.

Sorry, not sure what this entails.

Sorry, yes I know what index.php is but I'm not sure what you mean by the form 'going through' it.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30940
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: simple html post form not working

Post by Per Yngve Berg » Sun Jun 12, 2016 9:54 pm

That means you have to write your own component with models and views.

https://docs.joomla.org/Portal:Developers

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sun Jun 12, 2016 9:56 pm

Now that I don't understand! Will check out your link. Thanks.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Mon Jun 13, 2016 8:57 pm

Per Yngve Berg wrote:In Joomla all posts have to go through index.php.

You will be easier to use a forms extension or a cck.

I use Fabrik myself.
So what you are saying is that a plain simple HTML post form will not work without one of these extensions?

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: simple html post form not working

Post by sozzled » Mon Jun 13, 2016 9:40 pm

Snewzer wrote:So what you are saying is that a plain simple HTML post form will not work without one of these extensions?
I don't think that's actually what Per was saying. In your case, you want to have a simple form in your Joomla website to update a MySQL database table. I understand that. I've done this kind of thing before.

The issue here is that you can't just "simply" write a piece of PHP and merely insert it anywhere in your Joomla website and expect it to work as you might hope. There are methods of using PHP with Joomla (there is a standard API) and that's what we're trying to help you understand. A few messages earlier in this topic I mentioned the use of Joomla modules—for me, these are fairly easy to write once you get the hang of them. There are also other products (CCKs and components like Fabrik) that allow you to hook your PHP into one or another table in your database.

Assuming you're trying to update a specific database table that you've created yourself (outside of what might be available in a component like Fabrik) it's possible to write something that will process a form. In my case, I've done that by writing a Joomla module and that's all I am saying. I don't have any experience with Fabrik or BreezingForms and I'm unable to comment on the features of those products, sorry.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Tue Jun 14, 2016 3:22 pm

Hi Sozzled, I think that I should go away and read 'Joomla for dummies' and come back when I understand a bit more about it as I'm struggling to follow the advice being given. So I can get an HTML post form to work if I write a Joomla module, is that what you are saying?
Going back to your earlier post, I am using the direct php extension. My 'Evaluate form.php' is just a php srcript executing a mysql query and updating a database, it doesn't need to interact with Joomla to my way of thinking, just execute the query, update the database and return me back to my Joomla article with the new updated values displayed.

NickC4555
Joomla! Explorer
Joomla! Explorer
Posts: 457
Joined: Sun Jan 30, 2011 10:09 am
Location: Leicester, UK

Re: simple html post form not working

Post by NickC4555 » Tue Jun 14, 2016 3:59 pm

I would go with sozzled's suggestion and use Fabrik. As well as doing what you need, it will take care of integrating with Joomla (and your template), provide security, a huge range of field types, responsive (bootstrap) form and list views, and still let you use your own php code whenever you need to customize it.

over
Joomla! Intern
Joomla! Intern
Posts: 83
Joined: Thu Jan 18, 2007 5:35 pm

Re: simple html post form not working

Post by over » Wed Jun 15, 2016 7:16 am

Snewzer wrote:....

Going back to your earlier post, I am using the direct php extension. My 'Evaluate form.php' is just a php srcript executing a mysql query and updating a database, it doesn't need to interact with Joomla to my way of thinking, just execute the query, update the database and return me back to my Joomla article with the new updated values displayed.
Your just... update the database ... is bypassing every security level of Joomla. Do not blame Joomla if you turn off the filters for text and fields.

Depending on what you want to achieve in the future there are different approaches as suggested above. I agree with Sozzeled that a very good start, if you want to add functionality to Joomla are Joomla modules. Start with something easy and create forms and database connections in the next steps. Read documentation and follow tutorials on how to do this in a most secure way. The handling of reading and writing databases are allways a security risk that has to be minimized or your system is on a VERY local machine.

Even if you want to use some helper addons you'd better learn some Joomla basics first.

Happy coding 8)

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Wed Jun 15, 2016 12:53 pm

Thanks Over, but don't worry... all this is on my local machine at the moment. I am nowhere near thinking about going live until I know more, especially about security. The official Joomla book is on its way to me and I just wanted to make a start on writing my article while waiting.
Thanks to all others for suggestions so far, I will get Fabrik and take it from there and no doubt I will be back soon with further questions if I still can't get it to work!

erichf
Joomla! Explorer
Joomla! Explorer
Posts: 325
Joined: Fri Feb 26, 2010 4:01 pm

Re: simple html post form not working

Post by erichf » Fri Jun 17, 2016 10:57 am

Since you're familiar with writing PHP, another short-cut method is to use the sourcerer extension from NoNumber. This extension allows you to insert PHP code in places where Joomla usually doesn't allow you to do so.

If you install the sourcerer extension, and then use it to insert your PHP code into an article or into a Custom type module, you'll likely get the result you're looking for. It's not quite the proper solution which is to create a new extension (probably a new component) but it works. There's a lot of code overhead that goes along with creating a new component, so you may want to wait on that until you've got more familiarity with Joomla.

Or use one of the extensions like RSForms or ProForms. I use RSForms a lot and it is very powerful and flexible and allows you to connect the form created in RSForms to custom database fields and to integrate your own scripts into the form processing.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Fri Jun 17, 2016 6:13 pm

Thanks erichf, I have already installed the direct php extension which allows me to write the php code and I was presuming would be equivalent to sourcerer for my purposes. PHP works fine and I can do other things with it in my Joomla article, its just the form that isn't working.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sat Jul 09, 2016 7:23 am

I have obtained the official Joomla book but that hasn't helped me, it's just written in a style that doesn't work for me, so I have sent off for another beginners guide.

I have installed Fabrik but can't find a tutorial which can get me started on it so I am struggling to make any sense of it. I have installed breezing forms lite, but again, can't find a tutorial which can help me.

I have installed DirectPHP and this seems to do the job. I have got my forms working fine, the only modification needed to the standard HTML code is to pass along the Joomla parameters as hidden values in the form.

The only difficultly that I am having is that my drop down select menus are very wide, far wider than the text that they contain. Has anyone encountered this problem and can offer a solution ?

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: simple html post form not working

Post by sozzled » Sat Jul 09, 2016 7:48 am

Snewzer wrote:The only difficultly that I am having is that my drop down select menus are very wide, far wider than the text that they contain. Has anyone encountered this problem and can offer a solution ?
Different question, different subject. It is much better in these "technical discussion forums" to discuss different issues in specific subjects. As a general answer, the width of a <select ...> element (assuming that's what you mean) can be adjusted with CSS as well as with its own width attribute.

On the other hand, when you refer to the word "menu", most menus in Joomla comprise <div><ul><li> ... </li></ul></div> constructs, so I'm not quite sure I understand your problem. A separate topic (with a reference to your website) may provide us with a better clue.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sat Jul 09, 2016 8:02 am

That was quick! Thanks Sozzled. Yes that's right, the < select ...> element in a HTML drop down select menu, I am trying to do everything the old fashioned way at the moment because I haven't learnt enough about Joomla yet to do things the Joomla way.
It would normally take the width of the longest entry, but mine is over twice as wide. Will try the suggestions you have given but I'm puzzled as to why it should be so wide to begin with.

I don't have a website yet, this is just code I am building to install into someone else's pre-existing Joomla site.

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: simple html post form not working

Post by sozzled » Sat Jul 09, 2016 8:14 am

Please create a new topic with a separate subject concerning your unrelated issue. But, as a general response, let me offer some advice.

Considering that you are unable or unwilling to provide us with access to your site, it makes it 99.9% impossible to figure an answer based on this generalised "something-isn't-quite-right" assessment or, for that matter, merely on a screenshot.

It's a bit like telephoning your doctor and saying, "I'm unhappy with my appearance. What is your professional opinion?" I think you know what your doctor would say in reply, don't you?

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Sat Jul 09, 2016 8:48 pm

Thanks for the replies. I had made it clear earlier that I no nothing\little about Joomla and hadn't done any coding of any kind for years, so please excuse the 'vagueness' of my enquires.

When I said 'Joomla website' I meant localhost, I do not have a website.

I think it better that I endeavour to learn more about Joomla and then come back if I still need help.

Sorry Javieruis88 but I do not understand the phrase ' ***** Manual signatures are NOT allowed ***** '.

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: simple html post form not working

Post by sozzled » Sat Jul 09, 2016 8:53 pm

@Snewser: ignore what javieruis88 wrote; his message was spam and it has been reported to the moderators to act upon as they see fit.

Snewzer
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Jun 12, 2016 11:27 am

Re: simple html post form not working

Post by Snewzer » Tue Jul 12, 2016 11:35 pm

Thanks to everyone. The form is working perfectly now. I have used the DirectPHP extension and passed along the Joomla parameters in the form posting to index.php (...thanks Per !).

It's probably nothing like what you guys would write but this is a simple hobby project of no great importance so it will do for now while I learn how to use Joomla properly.

I have sorted out my other problems (... different subject !) also so this should be the end of this post.

Thanks to everyone.


Locked

Return to “Joomla! 3.x Coding”