I want to put 1 variable in my send.php page and get its value by if statement on 2nd (page-contact-us.php)page,
because I have my form in 2nd page with

<form action="<?php bloginfo('template_directory');?>/send.php" method="post" id="contactform">

and in my first page (send.php) i have if statement like,

if($security=="10") {
    mail($to,$subject,$message); 
    $var='1';
}
else {
    $var='2';
}

and on my page-contact-us.php page I want to get this mentioned $var above,
and use this $var value with if else statement like,

if ($var = "1") {

               echo ('<span class="success">Success!</span>');
                }
        else if ($var = "2") {
               echo ('<span class="error">Error!</span>');
            }

How i can achive this ? this is not working for me. :(

Re: How to put 1 variable in first page and get value from 2nd page 80 80

Use sessions.
If send.php page is independent page (meaning not included by some other page), you have to start session (session_start() function) on the very first line of page code, and than initialize variables as session variables.

// send.php
//on the very begin of page should be started session with session_start(); function

if($security == "10") 
{
    mail($to, $subject, $message); 
    $_SESSION['var'] = $var = '1';
}
    else 
    {
        $_SESSION['var'] = '2';
    }



// page-contact-us.php
// again, on the very top of the page start your session with session_start();

if ($_SESSION['var'] = "1") 
{
    echo ('<span class="success">Success!</span>');
}
    else if ($_SESSION['var'] = "2") 
    {
        echo ('<span class="error">Error!</span>');
    }
Re: How to put 1 variable in first page and get value from 2nd page 80 80

Wow!!!!!!!
Thank you very so much Bro,
you solved my problem. :) its worked.
but i have 1 little more problem.
when I submmited my form.
it goes to send.php url like this,

/wp-content/themes/ExampleName/send.php

But my original url is this, of wordpress.

example.com/contact-us/

and when it goes to this url there is nothing shows.
and one litle problem is more there that the error msg is not showing on submit button if the form is filled incorrect or,

$security is not =="10"

what is the solution of that?

Re: How to put 1 variable in first page and get value from 2nd page 80 80

You should have second part of code in contact-us page.
Also you can use absolut URL as form action value.
<form action="http://example.com/contact-us" method="POST">

Re: How to put 1 variable in first page and get value from 2nd page 80 80

But in the action form is used send.php not contact-us

Re: How to put 1 variable in first page and get value from 2nd page 80 80

Action value is showing page that is called with form. If you.
If you want contact-us page after submiting, you'll need to put it in form action. I don't know any other way.

Re: How to put 1 variable in first page and get value from 2nd page 80 80
Member Avatar

You can redirect after form submission using header("Location: $location") in the form processing file.

commented: thanx +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.