vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Form action help (https://vborg.vbsupport.ru/showthread.php?t=319318)

Duckface 07-02-2015 07:16 PM

Form action help
 
Code:

action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
I require that on the form method, although I'm aware that vbulletin requires the variable name for the action method.

E.g:

Code:

<form name="upgrade" method="POST" action="{vb:raw _SERVER.PHP_SELF}">
So how can I have that in the variable format?

kh99 07-02-2015 07:21 PM

Does that not work? Or is it the htmlspecialchars() that you're wondering about? I think if you use vb:var instead of vb:raw it does htmlspecialchars() on the value.

Duckface 07-02-2015 08:11 PM

It's this page you see:

http://spawnscape614.co.uk/forums/reportuser.php?

And I'm trying to validate the first input for a test. And when clicking the send report button it simply reloads...
Appropriate html:
Code:

<form class="vbform block" action="{vb:raw _SERVER.PHP_SELF}">
<label for="username">Enter offender's name: </label>
                                <input type="text" class="primary textbox" id="name" name="username" tabindex="1" /></input><span class="error"> * <?php echo $usernameErr;?></span>
<input type="submit" class="button" value="Send Report" tabindex="1"  />
</form>

Appropriate php:

PHP Code:

$usernameErr "";
$username "";
if(isset(
$_POST['submit'])) {
   if (empty(
$_POST["name"])) {
     
$nameErr "Name is required";
   } else {
     
$name test_input($_POST["name"]);
   }
   
}

   function 
test_input($data) {
   
$data trim($data);
   
$data stripslashes($data);
   
$data htmlspecialchars($data);
   return 
$data;


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

Idk why it just reloads. And I tried the var instead of the raw and it didn't work.

Duckface 07-07-2015 01:17 PM

Could anyone up?

kh99 07-07-2015 03:08 PM

Sorry, I missed your response.

OK, I had to do a little test to figure these things out, but first you need method="POST" in your form tag. Second, the indexes into $_POST are the name attributes of the input fields, so if you want to check for submit, you want to add name="submit" to that tag like:
HTML Code:

<input name="submit" type="submit" class="button" // etc

If you don't have a name attribute, the input will not go into the $_POST array at all.

You also want to use 'username' when checking the name, since that's the value of the name attribute.

Duckface 07-08-2015 05:22 PM

Hmm it's still not working. Do you have skype? I'll pay for your assistance btw.

kh99 07-08-2015 05:28 PM

I can't really do that right now, but here's the test program I used. I just put it in a file called test.php and pointed my browser there. It's not a vbulltin file at all, just a simple php file.

PHP Code:

<form method="POST" class="vbform block" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="username">Enter offender's name: </label>
                <input type="text" class="primary textbox" id="name" name="username" tabindex="1" /></input><span class="error"> * </span>
<input name="submit" type="submit" class="button" value="Send Report" tabindex="1"  />

</form>
<br/><br/>
<?php

if (array($_POST) && count($_POST))
{
   
var_dump($_POST);
}   
else
   echo 
'$_POST empty';
?>


Duckface 07-09-2015 02:28 PM

Yes, what I put worked on a page without vbulletin; although it doesn't work inside a vbulletin page.

kh99 07-09-2015 02:32 PM

Oh, OK. Did you try this for the code:
PHP Code:

$usernameErr ""
$username ""
if(isset(
$_POST['submit'])) { 
   if (empty(
$_POST["username"])) { 
     
$nameErr "Name is required"
   } else { 
     
$name test_input($_POST["username"]); 
   } 
    


   function 
test_input($data) { 
   
$data trim($data); 
   
$data stripslashes($data); 
   
$data htmlspecialchars($data); 
   return 
$data



and you said you added name="submit" to the submit button, right?

It's hard to tell if that's everything you need without seeing the big picture. Where are you putting that code, if that a plugin, or is reportuser.php a custom script? (I guess it's not a vbuletin file so that's probably it).

Duckface 07-09-2015 02:53 PM

It's a basic custom file.

Here is the page:

http://spawnscape614.co.uk/forums/reportuser.php

It's not a plugin either. Would you like the entire template?


All times are GMT. The time now is 10:43 PM.

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.02345 seconds
  • Memory Usage 1,754KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_html_printable
  • (3)bbcode_php_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