The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Create PHP Email Submission
I'm trying to create a page that allows visitors to enter their email address to be added to a mailing list. I was going to just use the HTML <form>, but the 'mailto:' code keeps forcing email programs open, something that is messy and I don't want. Because of this I've elected to go with a PHP script instead.
Here is the code I have for the form itself: PHP Code:
I've tried creating a vB page as documented here but either the form php script is ignored or I get errors. Here is the vB page I created (called newslettersubscription.php): PHP Code:
And with this file it calls a template, one I created called newsletter_subscription: Code:
{vb:stylevar htmldoctype} <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html"> <head> <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title> {vb:raw headinclude} {vb:raw headinclude_bottom} </head> <body> {vb:raw header} {vb:raw navbar} <div id="pagetitle"> <!-- <h1>{vb:raw pagetitle}</h1> --> </div> <center><h2 class="blockhead">Newsletter Subscription</h2></center> <div class="blockbody"> <div class="blockrow"> </div> </div> {vb:raw footer} </body> </html> Any help would be greatly appreciated. |
#2
|
|||
|
|||
Try this: put the form php code in a php file (different from newslettersubscription.php, which you also need) and upload it to your server (form.lib.php has to be there too). Then create a new plugin using hook location global_start and this code:
PHP Code:
Then in your newsletter_subscription template, put {vb:raw mailform} where you want the form. |
#3
|
|||
|
|||
So here is my new code. First the page iteself (newslettersubscription.php):
PHP Code:
PHP Code:
Code:
{vb:stylevar htmldoctype} <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html"> <head> <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title> {vb:raw headinclude} {vb:raw headinclude_bottom} </head> <body> {vb:raw header} {vb:raw navbar} <div id="pagetitle"> <!-- <h1>{vb:raw pagetitle}</h1> --> </div> <center><h2 class="blockhead">Newsletter Subscription</h2></center> <div class="blockbody"> <div class="blockrow"> {vb:raw mailform} </div> </div> {vb:raw footer} </body> </html> Code:
ob_start(); include('form.php'); $mailform = ob_get_contents(); ob_end_clean(); vB_Template:reRegister('newsletter_subscription', ('mailform' => $mailform)); Did I follow your directions correctly? I appreciate your help in this. |
#4
|
|||
|
|||
There are a couple problems: one is that there was a typo in my post, in the plugin code it should be:
Code:
vB_Template::preRegister('newsletter_subscription', array('mailform' => $mailform)); Also, you have to use the same variable name in the template that you used in the preRegister statement, so your template should have: HTML Code:
{vb:raw mailform} ...or else change the plugin code to be Code:
vB_Template::preRegister('newsletter_subscription', ('newsletter_form' => $mailform)); |
#5
|
|||
|
|||
I spotted "mailform" as I posted, and edited my code accordingly.
But it still didn't work. The plugin (called MAILFORM): PHP Code:
Code:
vb:raw mailform Also, when I activate the plugin it causes an error while Searching the forum. |
#6
|
|||
|
|||
What you're doing should work, I think, but I just realized that there really is no reason to use a plugin, you could just put the plugin code in newslettersubscription.php, in the custom code section. And then you don't need to preRegister, you can just register like you're doing with the other variables. Sorry, I guess I was too tired last night to think straight.
Anyway, what I'd do next is see if $mailform has anything in it. You maybe could just echo() it then look at the page source (or maybe you'll just see it in the browser. |
#7
|
|||
|
|||
I thank you for trying. So I put the form.php code back into newslettersubscription.php and this is the error I get:
Parse error: syntax error, unexpected '<' in /home/fpaul46/public_html/forum/newslettersubscription.php on line 41 Here is the code: PHP Code:
Code:
<?php Warning: require_once([path]form.lib.php) [function.require-once]: failed to open stream: No such file or directory in [path]/newslettersubscription.php on line 45 Fatal error: require_once() [function.require]: Failed opening required '/home/fpaul46/public_html/forumform.lib.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/fpaul46/public_html/forum/newslettersubscription.php on line 45 |
#8
|
|||
|
|||
Well, don't put the form code in newslettersubscription.php, put the code that you had in the plugin. (in fact you can leave the preRegister for now, there's no reason it shouldn't work).
Did you upload form.lib.php to the same directory with newslettersubscription.php? At this point, maybe someone else has a better idea for you. |
#9
|
|||
|
|||
I hope I don't confuse things for you, but your entire form should be in the template being used (<form>...<div>...<input>...</div>...</form>... etc). Then when the submit button is clicked, send the data collected to the PHP file that processes it.
|
#10
|
|||
|
|||
Yeah, that would be another way to do it, but since the form code has calls to php functions in it, I thought it would be easier to use the ob_start()...ob_end_clean() thing. If you put it all in a template you'd ahve to take out the php calls, assign them to variables, register them, etc.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|