Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2012, 09:47 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default make a link that autofill an input in the linked page

Hi I need some help to make a little code: i have 2 page: page A and page B. In the page A there is an input text and a button
Example:
Code:
<form><input type="text" id="email"><input type="submit" value="Continue"></form>
I need that when you press Continue what you text in the input #email appears in the input text of the page B
Example:
Code:
<form><input type="text" id="email"><input type="submit" value="Register">
FOR EXAMPLE:
I'm in the page A i write my email on the input text one (#email) I click continue and i get redirected to page B where the input text two (#email) is autofilled with my email (that i write on page A)

I hope I made myself clear.
Reply With Quote
  #2  
Old 06-17-2012, 11:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, your page B needs to be a php script, if it isn't already. Also, I believe what you want in your input tag is name="email" instead of id, and your form needs an action, like

Code:
<form action="page_b.php"><input type="text" name="email"><input type="submit" value="Continue"></form>

Then in page_b.php (or whatever you want to call it), you would get the value of the email field in $_GET['email'], so you can use it in the value attribute of the input tag. But you would want to use htmlspecialchars() on it to make sure the user didn't enter html into the field, because that would cause an error. So page_b.php might be something like:

Code:
<?php

$email = htmlspecialchars(trim($_GET['email']));

echo '<form><input type="text" name="email" value="' . $email . '"><input type="submit" value="Register">';

I should mention that in the vbulletin code it's done a little differently, so if you are including vbulletin code in your script you might want to use the vbulletin functions.
Reply With Quote
  #3  
Old 06-18-2012, 08:08 AM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok this works like a charm but when i try to put this code on vbulletin i've some problems
Page A is in the header template and i have this code
Code:
<form method="post" action="register.php">
<input type="text" name="email"><input type="submit" value="Continue"></form>
When i click continue it says
Quote:
Your submission could not be processed because a security token was missing.

If this occurred unexpectedly, please inform the administrator and describe the action you performed before you received this error.
What's the problem?
Reply With Quote
  #4  
Old 06-18-2012, 10:54 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So what is page B, is that your own custom vb page? If so then try adding:

Code:
define('CSRF_PROTECTION', false);

before global.php is included. If your "page b" script will have more than one function, it's also possible to disable the check only for specific function.
Reply With Quote
  #5  
Old 06-18-2012, 11:00 AM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Page b is register php. Basically what i'm trying to do is to put an input text in the header, an user can write his email on it and then click continue, when he will click continue he will be redirected to register.php where the email input is autofilled
Reply With Quote
  #6  
Old 06-18-2012, 11:11 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, in that case, try adding this to your form in the header:

Code:
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
Reply With Quote
  #7  
Old 06-18-2012, 01:38 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok now the header code works (page A). I'm now making page B and so i make a plugin
Hook Location: register_form_complete
Title: Test
Php code:
PHP Code:
$email htmlspecialchars(trim($_GET['email']));

echo 
'<form method="get"><input type="text" name="email" value="' $email '"><input type="submit" value="Register">'
I tried but it didn't work in register.php i see the input text but in page a when i click continue i have to rewrite the email
Reply With Quote
  #8  
Old 06-18-2012, 01:47 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, well, like I said above since you're working in an existing vb script you need to do things the vb way, so I think what you want is this (but I haven't tried it):

Code:
if (empty($email))
{
	$vbulletin->input->clean_gpc('p', 'email', TYPE_STR);
	$email = htmlspecialchars_uni($vbulletin->GPC['email']);
}

Because the form is already set up to fill in the field with whatever's in $email. And the clean_gpc() function is used in vb instead of using $_GET[] directly.
Reply With Quote
  #9  
Old 06-18-2012, 02:03 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It works great thanks

--------------- Added [DATE]1340032478[/DATE] at [TIME]1340032478[/TIME] ---------------

The code is a little hard to understand. I want to see if the email input is an email or not and if it is an email it goes to the email input if it isn't it goes to the username input, i tried this code with no result what can i do?
PHP Code:
if (empty($email))
{
  if (
eregi("^([a-z0-9]|\\-|\\.)+@(([a-z0-9]|\\-)+\\.)+[a-z]{2,4}$"$email))
  {
    
$vbulletin->input->clean_gpc('p''email'TYPE_STR);
  }
  else
  {
        
$vbulletin->input->clean_gpc('p''username'TYPE_STR);
  }
    
$email htmlspecialchars_uni($vbulletin->GPC['email']);

Reply With Quote
  #10  
Old 06-18-2012, 02:22 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I can't follow all that. But there's a vbulletin function is_valid_email() that you can call. It just does this:

Code:
	return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>@,;]+\.+[a-z]{2,6}))$#si', $email);

But if what you're saying is that you have one input field named email, but it might be a user name, then I think you'd want to do this:

Code:
$vbulletin->input->clean_gpc('p', 'email', TYPE_STR);
$input_email = htmlspecialchars_uni($vbulletin->GPC['email']);
if (is_valid_email($input_email))
{
    if (empty($email))
    {
        $email = $input_email;
    }
}
else
{
    if (empty($username))
    {
        $username = $input_email;
    }
}

This probably bypasses the check for a valid/unused username, but that just means the user would just get an error after submitting.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:41 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04933 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (10)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete