Pass variables to another php page using a button - php

So if someone is logged in my script reads the values and stores it and sets it as variables then I'm trying to make a registration page for something that members can register in.
The script is simple
<div id="english1"><p id="english1p">تأكد من بياناتك ثم اضغط رز الموافقة</p><br>
<form class="register2" action="includes/register2.inc.php" method="post" name="register2form"
<p class="username">اسم المستخدم: <?php echo htmlentities($_SESSION['username']); ?></p>
<p class="email">الايميل: <?php echo htmlentities($_SESSION['email']); ?></p>
<p class="age">السن: <?php echo htmlentities($_SESSION['age']); ?></p>
<p class="coursetype">الكورس المراد التسجيل فيه: <?php echo $coursename; ?></p>
<p class="paymethod">طرق الدفع:</p><ol><li>طريقة</li>
<li>طريقة</li>
<li>طريقة</li>
</ol>
<p class="sure">للتأكيد اضغط تسجيل</p>
<input class="register2button"
type="button"
value="تسجيل"
onclick="" />
</div>
Ignore the letters you don't understand, it's arabic.
So the script reads variables and then I want when the member clicks the submit button, the page POST the variables to includes/register2.inc.php without input as the variables are already set.
How can I do that?

If you want to keep your <p> tags you can store all the variables you want to pass to the next page in <input type="hidden" value="some value" /> These boxes will not be shown on the page, but will pass along data with any request you send to your server.

You can store your value in hidden element and pass it to next page.
<form action="page name" method="post">
<input type="hidden" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>" />
<p class="username"> username : <?php echo htmlentities($_SESSION['username']); ?></p>
<input type="submit" name="submit" value="submit" >
</form>

Inside the form, instead of p you should use input for each parameter:
<input type="text" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>"/>
You can kept this input hidden also like:
<input type="hidden" name="username" value="yourvalue"/>
These input field value won't pass in next page in $_POST if you will use p you have to use input for this.

Related

WP PHP Form Fields are missing. Where are they?

This is a hopeful question. I am really, really PHP inexperienced. But I am trying to teach myself a thing or two. The organization I work for uses a WP site. I regularly work on it. I mostly do HTML and CSS (stuff I know about) but I was just digging around in the background and came across something I don't understand at all.
I made a test page here: http://all4ed.org/webinar-event/test-2/
There are two forms on the page. The first ends in a "submit button," the second ends in a "Register Button."
So far so good. I dug around the backend of the WP files, and found the content-webinar.php file and saw that it pulled the form in as an include with:
// The registration form. ?>
<?php if ($registration_required == 'yes'): ?>
<?php include ('assets/includes/webinar/inc-block-registration-form.php'); ?>
<?php endif;
Good, so far.
I went to the "inc-block-registration-form.php" file and here's where it gets weird:
The first form is done with this code:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="get">
<div>
<p>
<label for="token">Token</label>
<input type="text" name="token" />
</p>
<p>
<button>Submit</button>
</p>
</div>
</form>
This looks exactly like I thought it would. The second form is written like this:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="post">
<div>
<?php if ($webinars->error) : ?>
<p class="error"><?= $webinars->error ?></p>
<?php endif; ?>
<?php foreach ($webinars->form_data as $data) : ?>
<p><?= $webinars->build($data) ?></p>
<?php endforeach; ?>
<p>
<button>Register</button>
<input type="hidden" name="webinars_registration_submitted" value="<?= $post->ID ?>" />
<input type="hidden" name="webinars_registration_title" value="<?= get_the_title() ?>" />
<input type="hidden" name="webinars_registration_url" value="<?= get_permalink() ?>" />
<!-- fields necessary for AA -->
<input type="hidden" name="webinars_user_id" value="<?= get_current_user_id() ?>" />
<input type="hidden" name="webinars_type" value="<?= get_field('webinar_type') ?>" />
<input type="hidden" name="webinars_post_id" value="<?= get_the_ID () ?>" />
</p>
</div>
</form>
Huh???? Where is the "Your Name", "Your E-mmail Address," "Organization," "City, State," or "Question (This is optional)"
How does this work? Where is it pulling those fields from. Any insight would be appreciated. Thanks.

Empty $_POST in Wordpress Archive Page

I have a custom form in my wordpress theme archive.php file but I can't get the post of that form. It's empty.
I have these:
<?php print_r($_POST); ?>
<div class="filtros">
<h3>Búsqueda de documentos</h3>
<form action="#" method="post">
<input type="text" id="name" name="f_name" placeholder="Buscar" value="<?php echo $_POST['f_name']; ?>" />
<div class="dates">
<input type="text" id="inicio" class="date" name="f_inicio" placeholder="Fecha de inicio" value="<?=$_POST['f_inicio']?>" /> /
<input type="text" id="final" class="date" name="f_final" placeholder="Fecha final" value="<?=$_POST['f_final']?>" />
</div>
<div class="submit"><input type="submit" value="Buscar" /></div>
</form>
</div>
Even if I pass the variables throw the URL I cant get that vars with $_GET.
¿Any idea?
While it's not advisable from a security point of view, you can change the method on your form from method="post" to method="get" to have variables posted as $_GET variables instead.
Change action="#" to action="<? echo $_SERVER['REQUEST_URI']?>"
Try change <?= to <? echo
You may need to point the action="myfile.php" to specific file.. See the solutions here:
$_POST returns empty on form submit in wordpress

How to pass the data in the input type using php

Hi, I want to know how to pass the data into the input type field; I'm using only $_POST method and also I did not use the database first. Please help.
form.php
<form action="booking.php" method="post">
<p>
I want to be pick up at:
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="pickupplace" id="pickupplace" autocomplete="off" tabindex="1" style="width: 260px;"/>
</p>
<p>
drop off at
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="dropoff" id="dropoff" autocomplete="off" tabindex="2" style="width: 260px;" />
</p>
</form>
in the booking.php
<div>
<p>From</p>
<p>
<p>
<?php
if(isset($_POST['pickupplace']) == NULL){
echo "-";
}
else{
echo $_POST['pickupplace'];
}
?></p>
</div>
in the edit_ride.php
<div>
<p>From</p>
<p>
<input type="text" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>
</p>
</div>
i want to pass the data into the edit_ride.php in the input type please help here it is,
What you can do is, you can merge edit_ride.php and booking.php, so that directly you can display the values using
<input type="text" name="pickupplace" value="<?php echo $_POST['pickupplace']" placeholder="Enter Address, Airport, Landmark"/>
This may not be the only solution, as some time we need multiple pages, in that case you may consider sessions or cookies also.
Alternatively, you can pass the values from one page to another using querystring ($_GET) method also without submit the forms in internal pages.
why are you specifying the form action booking.php if you need to submit your data on edit ride.php
so first of all change the form action to edit_ride.php and then recieve the data in your textbox as following on the page edit_ride.php
<input type="text" value="<?php if(isset($_REQUEST['pickupplace'])) echo $_REQUEST['pickupplace']; ?>" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>

How to echo this value into html upon successful login Php

<div class="content clearfix">
<div class="left">
<!--info-->
</div>
<?php
if(!$_SESSION['id']):
?>
<div class="left">
<!-- Login Form -->
<form class="clearfix" action="" method="post">
<h2>Login</h2>
<?php
if($_SESSION['msg']['login-err'])
{
echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
unset($_SESSION['msg']['login-err']);
}
?>
<input class="field" type="text" name="username" id="username" value="User" size="23" onFocus="clearText(this)" />
<input class="field" type="password" name="password" id="password" value="Pass" size="23" onFocus="clearText(this)" />
<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> Remember me</label>
<div class="clear"></div>
<input type="submit" name="submit" value="Login" class="bt_login" />
</form>
</div>
<div class="left right">
<!-- Register Form -->
<form action="" method="post">
<h2>Sign Up!</h2>
<?php echo $id; ?>
<?php
if($_SESSION['msg']['reg-err'])
{
echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
unset($_SESSION['msg']['reg-err']);
}
if($_SESSION['msg']['reg-success'])
{
echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
echo $_SESSION['id'];
unset($_SESSION['msg']['reg-success']);
}
?>
I basically want to output the version of the $_SESSION['id']; into html upon submission so that it can be grabbed from the page as a user navigates the site. So, if a user were to go to index2.php and logged in successfully, their ID (the PK for their username and pass combo) would be outputted to HTML so the code could grab that if say they go to prof.php next, that session var ID from $_SESSION['id']; could be grabbed by the page and used on prof.php if a user were to submit the form on prof.php
Can someone please help me be able to reuse this ID over and over as pages are navigated?
Thanks
It sounds to me like you want the id variable to be accessible across all of the pages a user visits.
That is exactly what session is designed to do. You don't want to be writing the value to the page, since unless you put it in a form, and resubmit the form, the server side will never receive it again.
Check out this reference

Showing form data after submit

I have a form with a submit button and a handler that stores data in the database. Problem is when the form is submitted, all data is cleared from the input fields. Is there a way to still show them after submit? What changes do I need to make to my form_submit function?
function mymodule_form_submit($form, &$form_state) {
//how to retain the input in the form
}
I'm looking for the most "drupalish" way to get this done?
As indicated by this previous StackOverflow question you can accomplish this with $form_state['storage'] and $form_state['rebuild'].
You can access the data using $_REQUEST['form_variable_name'] where form_variable_name is the name of the html input tag.
You then need to render the page back putting this value into the input tags value field.
<form method="POST" action="/account/contactdetails/">
<div>
<label>First name:</label>
<input type="text" name="firstname" value="<?php echo $_REQUEST['firstname']; ?>" />
</div>
<div>
<label>Last name:</label>
<input type="text" name="lastname" value="<?php echo $_REQUEST['lastname']; ?>" />
</div>
<input type="submit" value="Save" />
</form>

Categories