The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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> Example: Code:
<form><input type="text" id="email"><input type="submit" value="Register"> 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. |
#2
|
|||
|
|||
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. |
#3
|
||||
|
||||
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> Quote:
|
#4
|
|||
|
|||
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. |
#5
|
||||
|
||||
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
|
#6
|
|||
|
|||
OK, in that case, try adding this to your form in the header:
Code:
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" /> |
#7
|
||||
|
||||
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:
|
#8
|
|||
|
|||
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. |
#9
|
||||
|
||||
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:
|
#10
|
|||
|
|||
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. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|