I know this is not a drupal forum but, as I’m not getting any response there, I decided to give it a shot here.
I’m creating a web site that accepts custom content from users. So, for that matter, this site has a form and a custom module. Instead of using admin theme, this form is placed inside custom template which is created to have a uniform look with the rest of the pages. As a result, creating form elements through hook_form is out of question. Here’s where my problems lie. As this form uses custom theme, I’m not sure as to what can I do to make drupal know that user is submitting new content data when the form is submitted?
Would I need to use same query string that of content submission page of admin page like - ?q=node/add/page for action attribute of the html form?
(OR)
the only way is to map the url to my custom function and invoke some sort of hook inside of it?
Thanks
You can literally create any markup you want for your form, all you need to do is use the #theme attribute when you define the form. With it you can set theme functions for the form itself and any of the elements.
It is a very bad idea, not to use Drupal's FAPI. It solves so many problems for you, and not using it would be the first step to take if you want to open up a security hole in your site. A development framework like Drupal is not of much worth, if you don't use it's APIs.
Edit:
First thing to do, is to go to Drupal's FAPI reference. You can learn almost everything about the FAPI there.
You could use a template if you want, is just basic Drupal theming, but I would advise against it. It would be a lot more maintainable if you created theming functions for all the elements and used that instead, you could just loop through all the elements and render them like Drupal does, instead of having to edit a template file each you need to change the form. It might be a but more work now, but there's a reward to that work: cleaner and more maintainable code.
In code it looks something like this:
$form['item'] = array(
...
'#theme' => 'theme_function',
);
Doing this, the element will be rendered using the "theme_function". You can see an example of such a theme function for textfields.
Related
I am customizing a theme and a plugin in Wordpress. The plugin has a button where a user can click to bring up a form where they can ask a question. I want users to use post questions through this button on this plugin, but I don't fancy the visuals on it. So I thought I'd make a form on my landing page that will post into the plugin's form. If this is a terrible idea in the long run, please feel free to let me know because I am still new to web dev.
So the goal is to create a new form whose aesthetics are to my liking but still use the plugin's built in posting capability. How do I make my form paste into the plugin's form and then submit it? You'll notice that my form has 1 additional field: the add money field. I also need to integrate this into the plugin. If anyone know how to begin modifying the code for this I'm all ears to anything I need to start reading or a general way of how to approach this.
My form
Plugin's form
Summary:
Need to have my form paste to plugn form and submit
Need to add a field to the plugin code that my form can post to similar to how the other fields will do do
You can post from a different form if you get the destination URL or javascript that is handling the original form post. You can use the debugger in Firefox or Chrome to inspect the page contents to see how the form is handled.
Adding the money field will be more complicated because you will need to update the server side handling to accept the additional parameter so that it is not simply ignored or causing errors. How much work this is depends on what the server has to do. It may involve adding a column to the database or creating a new table which you will likely want to do the wordpress way if you want to have something that is maintainable.
Lastly keep in mind, that every time the original plugin is updated, it may bust your add on code unless you create your own plugin from the original.
I see all sorts of people asking this but no solid answers. I want to take text from a textarea form where users can enter their bio and then insert it into the bio field in mysql. This might be fairly easy normally, but alas, it seems nearly impossible with WordPress. I have to use the "Php for posts and pages" plugin and for some reason, the php script I have cannot be found (404 error) no matter where I place it. Then I thought I would try to just make the form and php all on one WordPress page, but it apparently can't be done like on a normal php web page. Anyone have any experience doing this? Any approaches that are known to work?
You can make form using normal php and insert it into mysql.
You can do this by making page template in wordpress.
http://codex.wordpress.org/Page_Templates
I've went through the same process! :)
My solution was:
Installing a PHP insertor plugin (specifically this). It's lot easier than creating a template.
I used it like this (inserted into the post's source):
[insert_php] include('myphpfile.php'); [/insert_php]
Then the included PHP's contents will be processed and printed out inside the page's body (the article's main part), so you don't have to create the html, head and body tags.
Then came the problem with posting form data to a page like this. This was because some of my form's fields kinda conflicted with WP's variables.
Some of the conflicting field names I've noticed: info, name
Just have a look at your form' field names and replace them to something else, and everything will be fine! :)
PS.: It's possible to put the form and the form data "receiver" in the same PHP script. I've done so and it worked in this scenario.
PS. 2: Optionally, you can disable the annoying auto-paragraph-insertor wpautop stock WP plugin, as it's affecting the included PHP's output. There is a per-post wpautop disabler plugin: Toggle wpautop
it may seem like a dumb question because I feel like it is when asking it but I can't find anything about it in the doc.
I need to put a form in the header of my website that appears in all pages.
I need that form to be able to be submitted in every page (no surprise here).
I can display my form via the layout function of Zend Framework, but I can't find the equivalent for the back-end of the website to be able to treat it at only one place, site-wide.
I thought it would be possible to put the form validation in the bootstrap but it doesn't seem like it.
Did I miss something or do I have to, at least, put the form validation in all init() function of all my controllers ?
take a look at the plugin documentation
You can write a plugin that handles your request. If you need to have your form processed before any other actions take place, I suggest you use the dispatchLoopStartup() hook.
You should avoid predispatch and postdispatch in this case, because those hooks are called multiple times if you proces multiple actions (by using _forward for instance)
I have a situation where I have several ways to perform the same activity in my php web app.
There is the "Manage Widgets" section of the app which has a form for creating new widgets and a list of existing widgets.
Then somewhere else in the app there is a button that pops up a dialog to add a new widget.
Then on the home page of the app there is another place where a form is embedded to add a widget (think home page portal).
My question is: What is the best practice for this? In this case all of the forms will be essentially the same. So my first instinct is to use the same code for all three of these scenarios. On the other hand, space on the home page could be smaller and layouts may have to differ between the three.
So even though it would be repetition, is it better to duplicate this form 3 times (there is a proper model layer, so the duplicated code would not include the logic to add/edit the widget)? Or try to force a single view in all of these scenarios? Both seem wrong to me and I am hoping for some ideas to discover some sort of middle ground.
One approach would be to have the markup (not the styles) for the form as a standalone file, which can then be included from anywhere you like.
You can then use AJAX to submit the form to a specific PHP script that handles the form submission and returns a meaningful JSON response. You can then display and style this JSON response on the page in question.
This way you have a single form (that can be styled differently) and a single handler for any view that's required to use the form.
i mean, the best way is compose form from other forms (Dont repeat yourself). You can use different templates for same form to change appearance of final form.
For example/idea you can check forms what is used in Nette Framework (http://doc.nette.org/en/forms)
T.
If you are just changing the styles, not the markup, I think the best approach is to add a specific class to the form element and then use Javascript (not Ajax, justa Javascript) to alternate between these clases as you need.
If your application do not use Ajax at all and you just generate web pages with PHP, is a simple matter of decide which class you form shoud have.
In CSS, you do something like this:
form.main { ... }
/* main form rules */
form.other { ... }
/* other form rules */
I'm building a website using Wordpress. The WP-Events plugin is being used to display a list of upcoming events. What I need is for people to be able to confirm their attendance at any particular event.
WP-Events is a bit awkward in that it's customised using a template that is only able to be edited with the Wordpress admin. I used this template in combination with the Wordpress 'Loop' to generate a form for each event that could be filled in and submitted. I then was going to use jquery to toggle the display of each form as to not make the page massive. This plan collapsed when I wasn't able to implement any form validation.
What I have now is a list of events on one page, and a confirmation form on another. What I now need is to pull the event name, date and location from the selected event, and pass them across for use in the form. The problem is that wordpress' permalink structure doesn't seem to allow me to add a variable (ie. example.php?variable=1 ).
It it possible to do this?
thanks in advance,
Greg.
Unless you modified something, out of the box Wordpress will allow you to use GET variables, because it uses them too (for previewing posts).
If you installed something that removed all of the GET parameters, you might want to uninstall that. But out of the box Wordpress will let you use GET parameters.
I have tried both GET and POST with no effect. If you have PHP processing a GET variable on a WP Page, the URL is:
/page/?variable=something
And PHP is not recognizing this at all.
Use add_query_arg function. Codex.