vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   make a link that autofill an input in the linked page (https://vborg.vbsupport.ru/showthread.php?t=284569)

Scanu 06-17-2012 09:47 PM

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.

kh99 06-17-2012 11:48 PM

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.

Scanu 06-18-2012 08:08 AM

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?

kh99 06-18-2012 10:54 AM

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.

Scanu 06-18-2012 11:00 AM

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

kh99 06-18-2012 11:11 AM

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

Code:

<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />

Scanu 06-18-2012 01:38 PM

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

kh99 06-18-2012 01:47 PM

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.

Scanu 06-18-2012 02:03 PM

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']);



kh99 06-18-2012 02:22 PM

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.


All times are GMT. The time now is 04:11 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.01149 seconds
  • Memory Usage 1,749KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete