Storing SESSION data all within a single form [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to store data in $_SESSION variables so I can use it in other parts of the form.
I have an input for team name which I need to use within a drop down a couple of steps down the form, the team name come from the user input only.
Im struggling to pass this data throughout the form and then post it at the end.
The session is being set in header.php
<?php
if(!empty($_POST)) {
$_SESSION['dashboardName'] = $_POST['dashboardName'];
$_SESSION['teamName'] = $_POST['teamName'];
$_SESSION['firstName'] = $_POST['firstName'];
$_SESSION['lastName'] = $_POST['lastName'];
$_SESSION['memberTeam'] = $_POST['memberTeam'];
$_SESSION['stenData'] = $_POST['stenData'];
$_SESSION['score_1'] = $_POST['score_1'];
$_SESSION['score_2'] = $_POST['score_2'];
$_SESSION['score_3'] = $_POST['score_3'];
$_SESSION['score_4'] = $_POST['score_4'];
$_SESSION['score_5'] = $_POST['score_5'];
$_SESSION['score_6'] = $_POST['score_6'];
$_SESSION['score_7'] = $_POST['score_7'];
$_SESSION['score_8'] = $_POST['score_8'];
}
?>
<form action="" method="POST">
<!-- STEP :: 1 -->
<div class="step-one">
<h1>STEP 1</h1>
<input type="text" name="dashboardName" required placeholder="Dashboard Name" value="<?php echo $_SESSION['dashboardName']; ?>">
<button class="step-one-next">Next</button>
</div>
<!-- STEP :: 2 -->
<div class="step-two">
<h1>STEP 2</h1>
<input type="text" name="teamName" placeholder="Team name" required value="<?php echo $_SESSION['teamName']; ?>">
<button class="step-two-previous">Previous</button>
<button class="step-two-next">Next</button>
</div>
<!-- STEP :: 3 -->
<div class="step-three">
<h1>STEP 3</h1>
<input type="text" name="firstName" placeholder="First Name" required value="<?php echo $_SESSION['firstName']; ?>">
<input type="text" name="lastName" placeholder="Last Name" required value="<?php echo $_SESSION['lastName']; ?>">
<button class="step-three-previous">Previous</button>
<button class="step-three-next">Next</button>
</div>
<!-- STEP :: 4 -->
<div class="step-four">
<h1>STEP 4</h1>
<select name="memberTeam">
<option><?php echo $_SESSION['teamName']; ?></option>
</select>
<button class="step-four-previous">Previous</button>
<button class="step-four-next">Next</button>
</div>
<!-- STEP :: 5 -->
<div class="step-five">
<h1>STEP 5</h1>
<textarea name="stenData" placeholder="Paste Sten Data..." required><?php echo $_SESSION['stenData']; ?></textarea>
<button class="step-five-previous">Previous</button>
<button class="step-five-next">Next</button>
</div>
<!-- STEP :: 6 -->
<div class="step-six">
<h1>STEP 6</h1>
<select name="score_1">
<option selected="selected"><?php echo $_SESSION['score_1']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_2">
<option selected="selected"><?php echo $_SESSION['score_2']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_3">
<option selected="selected"><?php echo $_SESSION['score_3']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_4">
<option selected="selected"><?php echo $_SESSION['score_4']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_5">
<option selected="selected"><?php echo $_SESSION['score_5']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_6">
<option selected="selected"><?php echo $_SESSION['score_6']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_7">
<option selected="selected"><?php echo $_SESSION['score_7']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select name="score_8">
<option selected="selected"><?php echo $_SESSION['score_8']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button class="step-six-previous">Previous</button>
<button class="step-six-next">Next</button>
</div>
<!-- STEP :: 7 -->
<div class="step-seven">
<h1>STEP 7</h1>
<p><?php echo $_SESSION['dashboardName']; ?></p>
<button class="step-seven-previous">Previous</button>
<input type="submit" name="test" value="Submit">
</div>
</form>
<script>
$(".step-one-next").click(function(){
$(".step-one").hide();
$(".step-two").show();
});
$(".step-two-previous").click(function(){
$(".step-two").hide();
$(".step-one").show();
});
$(".step-two-next").click(function(){
$(".step-two").hide();
$(".step-three").show();
});
$(".step-three-previous").click(function(){
$(".step-three").hide();
$(".step-two").show();
});
$(".step-three-next").click(function(){
$(".step-three").hide();
$(".step-four").show();
});
$(".step-four-previous").click(function(){
$(".step-four").hide();
$(".step-three").show();
});
$(".step-four-next").click(function(){
$(".step-four").hide();
$(".step-five").show();
});
$(".step-five-previous").click(function(){
$(".step-five").hide();
$(".step-four").show();
});
$(".step-five-next").click(function(){
$(".step-five").hide();
$(".step-six").show();
});
$(".step-six-previous").click(function(){
$(".step-six").hide();
$(".step-five").show();
});
$(".step-six-next").click(function(){
$(".step-six").hide();
$(".step-seven").show();
});
$(".step-seven-previous").click(function(){
$(".step-seven").hide();
$(".step-six").show();
});
</script>
So the end goal is to input the inputs at each stage, name the team and then the team names be available in the drop down on the memberTeam <select>

Every time you hit Next button, the form data don't post to server. You can change to <button type="submit" class="step-one-next">Next</button> (add type as submit), but you need to handle which step you're in and which step is next when hit Next. Otherwise, it's easier to use JavaScript.
Updated using jQuery:
https://jsfiddle.net/79nj8e7p/1/
Sorry, I don't have enough reputation to put as comment.

Related

Adding number from input field to specific option selected row into SQL table

I am trying to use both an input field to add a number to a current row while also using an input field to select the specific row.
<form>
<div class="form-group">
<select class="form-control" id="rowid">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</div>
<div class="form-group">
<input type="number" class="form-control" id="numbertoadd" placeholder="1,000">
</div>
<button type="button" class="btn btn-danger" style="height: 38px;">Remove</button>
</div>
</form>
I have tried looking into other ways people have done this such as with the sql:
UPDATE user SET points = points + 1 WHERE id = 42
But i am unsure how i can use both selected fields at the same time.

How to get value from combobox into next url

I wonder if anyone can help my problem, in which way I can get value from combobox selection into next url by clicking so I can make it as a parameter to the pdf report.
this is my code to add some combobox :
<form method="GET">
<label class="col-sm-3 control-label">Bulan</label>
<div class="col-sm-2">
<select name="bln" class="form-control">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<option value="8">Agustus</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>
</div>
<br>
<br>
<label class="col-sm-3 control-label">Tahun</label>
<div class="col-sm-2">
<select name="thn" class="form-control">
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
</select>
</div>
</form>
<?php
if (isset($_GET['bln'])) {
$bln = $_GET['bln'];
$thn = $_GET['thn'];
}
?>
<a class="btn btn-success" href="rep-cuti-tahunan-all.php?bln="$bln"&thn="$thn"">Print</a>
so I would like to put $bln and $thn into <a class="btn btn-success" href="rep-cuti-tahunan-all.php?bln="$bln"&thn="$thn"">Print</a>
and get my report in pdf exactly according to that parameters
any suggestions?
You don't have to add it as a parameter.Just change your form like this.
<form method="GET" action ="rep-cuti-tahunan-all.php">
....
</form>
then on your php file, you fetch the selected value.
<?php
....
if (isset($_GET['bln'])) {
$bln = $_GET['bln'];
$thn = $_GET['thn'];
}
....
//Do your print method ...
?>

Post selected option's value to second page using sessions

I've been trying to post the value of two selected dropdown menu's using the SESSIONS method, however there seems to be an issue because when submitted the second page displays the PHP code only. Here are the relevant snippets of code:
shop.php
<form action="processing.php" method="post"> <div class="item">
<span class="caption">Essential Gray Suit<br />£459</span>
<select name="size1" class="size" id="size1" onchange="showDiv(this)">
<optgroup label="Size">
<option value="0">SELECT SIZE</option>
<option value="1">XS</option>
<option value="2">S</option>
<option value="3">M</option>
<option value="4">L</option>
<option value="5">XL</option>
</select>
<div id="quantity1" style="display: none;">
<select name="quantity1" class="size" onchange="showCart(this)">
<optgroup label="Quantity">
<option value="0">SELECT QUANTITY</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<input type="submit" value="Submit" name="submit" id="submit">
</form>
processing.php
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['size1'] = $_POST['size1'];
}
echo $_SESSION['size1'];
?>

How do I limit form options based on previous entry & leave all fields (including file selection) populated on submittion

I have the current form:
<form name="estimate" action="live_preview.php" method="post"enctype="multipart/form-data">
<label for="file">Upload File 1:</label>
<input type="file" name="file" id="file"/>
<label for="qty1">Quantity:</label>
<select name="qty1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<label for="file">Upload File 2:</label>
<input type="file" name="file2" id="file2"/>
<label for="qty2">Quantity:</label>
<select name="qty2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<label for="file">Upload File 3:</label>
<input type="file" name="file3" id="file3"/>
<label for="qty3">Quantity:</label>
<select name="qty3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<label for="file">Upload File 4:</label>
<input type="file" name="file4" id="file4"/>
<label for="qty4">Quantity:</label>
<select name="qty4">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<label for="file">Upload File 5:</label>
<input type="file" name="file5" id="file5"/>
<label for="qty5">Quantity:</label>
<select name="qty5">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<br>
<label for="meterial">Meterial:</label>
<select name="material">
<option value="PLA">PLA (0.60$ / Gram)</option>
<option value="ABS">ABS (0.60$ / Gram)</option>
<option value="POLYCARB">PolyCarb (1.80$ / Gram)</option>
<option value="NYLON">Nylon (1.20$ / Gram)</option>
</select>
|
<label for="color">Color:</label>
<select name="color">
<option value="WHITE">White</option>
<option value="BLACK">Black</option>
<option value="RED">Red</option>
<option value="GREEN">Green</option>
<option value="GRAY">Gray</option>
</select>
|
<label for="delivery">Delivery Method:</label>
<select name="delivery">
<option value="PICK UP">Pick Up (Free)</option>
<option value="SHIPPED">Shipped (+10$)</option>
</select>
|
<label for="marketing">Marketing?</label>
<select name="marketing">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
<br>
<label for="infill">Infill: 20%</label>
<input type="range" name="infill" id="infill" value="20" min="20" max="90" step="10" onchange="printValue('infill','rangeValue1')"/>
90%
<input id="rangeValue1" type="text" size="2"/>
<br>
<ul class="buttons vertical">
<input type="submit" class="button fit scrolly" name="submit" value="Refresh Estimate" />
</ul>
</form>
What I'm trying to do is:
Being able to limit the colour selection based on the type of material previously chosen
Upon submission, process php file while still keeping all fields populated so that if user isn't happy with price given, they can modify some settings and get a new "estimate"
have the following actions happen w/o a page refresh (not a priority)
Thank you very much for taking the time to read this! Its extremely appreciated.
1.
This would be achieved with client-side code. Javascript / jQuery is what you need here.
2.
Unfortunately, file fields can't be kept populated when you reload the page (or redirect back). You can keep them populated by using AJAX to send your form contents, but it can be quite complex and sending files with AJAX will only work in modern browsers.
3.
AJAX is what you are looking for if you want server actions to happen without a page refresh. Look at jQuery $.post. My suggestion is that you have your form which people begin to fill out. The site will check the inputs along the way and suggest prices without refreshing the page, and once they are happy and ready to go, they submit the form which will upload the files and "refresh the page".
on 2, php only solution: You can keep the fields populated on submission by adding a placeholder to the input field. The placeholder gets the submitted value ($_POST('value') or similar). Just make sure that the value isn't lost if you have several fields and thus several submits before the customer hits the final "all fine" button, maybe use $_SESSION for that.

Update combobox fail

i'm trying to use comboboxes for quantity in Virtuemart instead of quantity text and update button.
When i have only one article in the cart it works perfectly, but when i have more than one, it's not working.
Here's the form code
<form action="<?php echo JRoute::_ ('index.php'); ?>" method="post" class="inline" name="frm">
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="text" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>.2" class="inputbox" size="3" maxlength="4" name="quantity" value="<?php echo $prow->quantity ?>" style="display:none;"/>
<select name="cantidad" id="cantidad" onchange="getval(this);" value="<?php echo $prow->quantity ?>" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>"> <script type="text/javascript">
function getval(sel) {
document.frm.quantity.value = (sel.value);
document.getElementById('actualizar').click();
}
</script>
<option value="<?php echo $prow->quantity ?>"><?php echo $prow->quantity ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select>
<input type="hidden" name="view" value="cart"/>
<input type="hidden" name="task" value="update"/>
<input type="hidden" name="cart_virtuemart_product_id" value="<?php echo $prow->cart_item_id ?>"/>
<input type="submit" class="vmicon vm2-add_quantity_cart" id="actualizar" name="update" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>" align="middle" value=" " style="display:none;"/>
</form>
Thank you

Categories