renaming form fields

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
sewingtheseeds
Forum Newbie
Posts: 1
Joined: Tue Jan 12, 2016 5:06 pm

renaming form fields

Post by sewingtheseeds »

hello all. i ran across a super simple shopping cart template that i really like. the html have no text fields only only drop downs and selections with 4 values to pass but i'm having a difficult time changing the code side of the template. as i mentioned there are only 4 values that need be passed on to the php script. my question is am i right in supposing that i can merely substitute the field names and id, in the html code, with the 4 names and id that i would like to use?
the database has been set up and a connection is established via php. this is actually the last piece of the puzzle. lol. until i get the html right i can't see what values are being passed to the db. i think that there are 5 form fields with the following names: " prod2_color1, prod2_qty1, prod2_color3, prod2_size1 and prod2_size3". as i asked previously is it possible to just substitute form field names with the ones i want (description, temple, quantity, price)?

the code looks like this:

Code: Select all

<form id="shoppingCart" method="POST" class="form-inline" name="basket_form" action="myconnection/prac0.php">
				<div class="content">
                    <div class="navbar">
                        <div class="navbar-inner">
                            <ul class="nav custom_nav">
                                <li class="pull-left">
                                    <div>
                                        <a href="http://xxxx.co" class="btn btn-info">
                                            <i class="icon-hand-left icon-white"></i>
                                            Continue Shopping
                                        </a>
                                    </div>
                                </li>
                   <li class="pull-right">
    <a href="http://xxxx.co/checkout.html">
        <span class="btn btn-success continue_to_checkout" type="submit" value="Checkout" name="cont_to_checkout1">
            Continue To Checkout
        </span>
    </a>
</li>
                                <li class="pull-right">&nbsp;&nbsp;</li>
                                <li class="pull-right">
                                    <div>
                                        <button class="btn btn-danger remove_all" type="submit" name="remove_all1" value="remove_all" rel="tooltip" data-placement="bottom" data-original-title="Be careful! All products will be entirely removed from the basket!">
                                            <i class="icon-remove icon-white"></i>
                                            Remove All
                                        </button>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
					<div class="basket_list clearfix">
						<div class="tables">
						  <table class="table table_header">
								<thead>
									<tr>
										<th colspan="2" class="description">
											Item Description
										</th>
										<th class="temple">
											Temple
										</th>
										
								  <th class="quantity">
											Quantity
									  </th>
										<th class="price">
											Price
										</th>
										<th class="subtotal">
											Subtotal
                  </th>
										<th>&nbsp;
											
										</th>
									</tr>
								</thead>
							</table>
							<table class="table">
								<tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2"><a href="javascript: void(0);" title="Link to product page"><img src="img/331.jpg" alt="" width="123" height="91" title="Product Image"></a></td>
										<td class="description" rowspan="2">
											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Carat</a>
											<div>
												<div class="item-availability"><em>These Diamond Shape Spectacles Accentuate Anyone's Style and Grace</em>.</div>
												<div class="item-sku">MDL331</div>
											</div>
										</td>
										<td class="size">
                                            <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
                                            </select> 
								    </td>
										<td class="color">


											<input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
										</td>
								  <td class="quantity">Qty:								    <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
							      </td>
										<td class="price">
											<span class="currency">$</span><span class="amount">3000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">3000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
										</td>
									</tr>
							  </tbody>
					    </table>
                        
                        
                        <table class="table">
							  <tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2">
									  <a href="javascript: void(0);" title="Link to product page"><img src="img/332.JPG" width="123" height="91"></a></td>
										<td rowspan="2" class="description">
											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Minimum</a>
											<div>
												<div class="item-availability">
												  <p><em>Timeless Design, </em><em>A true work of art</em>, <em>High Quality Lenses, </em><em>A Comfortable Fit</em></p>
</div>
												<div class="item-sku">MDL332</div>
											</div>
										</td>
										<td class="size">
                                          <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
                                            </select>
										</td>
										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
									  </td>
								  <td class="quantity">Qty:								    <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
							      </td>
										<td class="price">
											<span class="currency">$</span><span class="amount">4000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">4000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
									  </td>
									</tr>
							  </tbody>
					    </table>
                        
                        
                        <table class="table">
						  <tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2">
											<a href="javascript: void(0);" title="Link to product page">
												<img src="img/333.jpg" width="123" height="91" title="Product Image">
											</a>
    </td>
										<td class="description" rowspan="2">
											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Maximum</a>
											<div>
												<div class="item-availability"><em>Rimless frames</em>, <em> Sophistication &  Elegance</em> by Design</div>
												<div class="item-sku">MDL333</div>
											</div>
										</td>
										<td class="size">
                                            <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
                                            </select>
										</td>
										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
									  </td>
										<td class="quantity"><label class="inline">Qty:</label><input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
										</td>
										<td class="price">
											<span class="currency">$</span><span class="amount">5000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">5000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
									  </td>
									</tr>
							  </tbody>
					    </table>
                       
                                                                  
                        <table class="table">
<tbody>
							    <tr class="warning">
							      <td class="thumb" rowspan="2"><a href="javascript: void(0);" title="Link to product page"></a><img src="img/POV_clip_image001.jpg" width="111" height="87"></td>
							      <td class="description" rowspan="2"><a class="item-name" href="javascript: void(0);" title="Link to product page">The Drop</a>
							        <div>
							          <div class="item-availability"><em>These Teardrop Cut Lenses with Lightweight Rimless frames are a work of art</em></div>
							          <div class="item-sku">MDL334</div>
						            </div></td>
							      <td class="size"><select class="span2" id="prod2_size3" name="prod2_size3">
							        <option value="Buffalo Horn" selected>Buffalo Horn</option>
							        <option value="Gold">Gold</option>
							        <option value="Rose Gold">Rose Gold</option>
							        <option value="White Gold">White Gold</option>
							        <option value="Titanium">Titanium</option>
							        <option value="Platinum">Platinum</option>
							        </select></td>
							      <td class="color"><input type="hidden" id="prod2_color3" name="prod2_color3" value="no"></td>
							      <td class="quantity"><label class="inline">Qty:</label>
							        <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini"></td>
							      <td class="price"><span class="currency">$</span><span class="amount">6000.00</span></td>
							      <td class="subtotal"><span class="currency">$</span><span class="amount">6000.00</span></td>
							      <td class="remove"><button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!"> <i class="icon-remove icon-white"></i> </button></td>
thanks for all your support.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: renaming form fields

Post by Christopher »

sewingtheseeds wrote:is it possible to just substitute form field names with the ones i want (description, temple, quantity, price)?
Yes, just change the name such as name="prod2_qty1" to name="quantity". As I said in the last thread, you just need to match the field name with the value in the $_POST array.

So the HTML:

Code: Select all

<input id="prod2_qty1" name="quantity" type="text" class="number" value="1" class="inline input-mini">
When the form is submitted, the value with be available in:

Code: Select all

$quantity = $_POST['quantity'];
(#10850)
sladepowers
Forum Newbie
Posts: 6
Joined: Tue Dec 01, 2015 6:34 pm

Re: renaming form fields

Post by sladepowers »

i tried it and it didn't work. bummer. i tried to use the order form and then check phpmyadmin and saw nothing in the table. so the first thing i did was run my php script to see what type of response i'd get. i got this message: "Connected to database
Array
(
)".

(although i don't know what is supposed to be in the array, errors perhaps? but it did take away the previous error message i was receiving regarding an integrity error and one of the values needed be set to null)
in any event, the good connection is there. next i made sure the correct string in the html code to access the php script was correct and it is. if i may here is the html:

Code: Select all

<form id="shoppingCart" method="POST" class="form-inline" name="basket_form" action="myconnection/prac0.php">
				<div class="content">
                    <div class="navbar">
                        <div class="navbar-inner">
                            <ul class="nav custom_nav">
                                <li class="pull-left">
                                    <div>
                                        <a href="http://eyewasframed.co" class="btn btn-info">
                                            <i class="icon-hand-left icon-white"></i>
                                            Continue Shopping
                                        </a>
                                    </div>
                                </li>
                   <li class="pull-right">
    <a href="http://eyewasframed.co/checkout.html">
        <span class="btn btn-success continue_to_checkout" type="submit" value="Checkout" name="cont_to_checkout1">
            Continue To Checkout
        </span>
    </a>
</li>
                                <li class="pull-right">&nbsp;&nbsp;</li>
                                <li class="pull-right">
                                    <div>
                                        <button class="btn btn-danger remove_all" type="submit" name="remove_all1" value="remove_all" rel="tooltip" data-placement="bottom" data-original-title="Be careful! All products will be entirely removed from the basket!">
                                            <i class="icon-remove icon-white"></i>
                                            Remove All
                                        </button>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
					<div class="basket_list clearfix">
						<div class="tables">
						  <table class="table table_header">
								<thead>
									<tr>
										<th colspan="2" class="description">
											Item Description
										</th>
										<th class="size">
											Temple
										</th>
										
								  <th class="quantity">
											Quantity
									  </th>
										<th class="price">
											Price
										</th>
										<th class="subtotal">
											Subtotal
                  </th>
										<th>&nbsp;
											
										</th>
									</tr>
								</thead>
							</table>
							<table class="table">
								<tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2"><a href="javascript: void(0);" title="Link to product page"><img src="img/331.jpg" alt="" width="123" height="91" title="Product Image"></a></td>
										<td class="description" rowspan="2">
											<a class="item-name" href="javascript: void(0);" title="http://exxxx.co/vantage_poxxxx.html">The Minimum</a>
											<div>
												<div class="item-availability"><em>These Diamond Shape Spectacles Accentuate Anyone's Style and Grace</em>.</div>
												<div class="item-sku">MDL331</div>
											</div>
										</td>
										<td class="size">
                                            <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
                                            </select> 
								    </td>
										<td class="color">


											<input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
										</td>
								  <td class="quantity">Qty:								    <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
							      </td>
										<td class="price">
											<span class="currency">$</span><span class="amount">3000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">3000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
										</td>
									</tr>
							  </tbody>
					    </table>
                        
                        
                        <table class="table">
							  <tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2">
									  <a href="javascript: void(0);" title="http://eyexxxxint.html"><img src="img/332.JPG" width="123" height="91"></a></td>
										<td rowspan="2" class="description">
											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Medium</a>
											<div>
												<div class="item-availability">
												  <p><em>Timeless Design, </em><em>A true work of art</em>, <em>High Quality Lenses, </em><em>A Comfortable Fit</em></p>
</div>
												<div class="item-sku">MDL332</div>
											</div>
										</td>
										<td class="size">
                                          <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
                                            </select>
										</td>
										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
									  </td>
								  <td class="quantity">Qty:								    <input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
							      </td>
										<td class="price">
											<span class="currency">$</span><span class="amount">4000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">4000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
									  </td>
									</tr>
							  </tbody>
					    </table>
                        
                        
                        <table class="table">
						  <tbody>
									<tr class="warning">
										<td class="thumb" rowspan="2">
											<a href="javascript: void(0);" title="Link to product page">
												<img src="img/333.jpg" width="123" height="91" title="Product Image">
											</a>
    </td>
										<td class="description" rowspan="2">
											<a class="item-name" href="javascript: void(0);" title="Link to product page">The Maximum</a>
											<div>
												<div class="item-availability"><em>Rimless frames</em>, <em> Sophistication &  Elegance</em> by Design</div>
												<div class="item-sku">MDL333</div>
											</div>
										</td>
										<td class="size">
                                            <select class="span2" id="prod2_size1" name="prod2_size1">
												<option value="Buffalo Horn" selected>Buffalo Horn</option>
												<option value="Gold">Gold</option>
												<option value="Rose Gold">Rose Gold</option>
												<option value="White Gold">White Gold</option>
												<option value="Titanium">Titanium</option>
												<option value="Platinum">Platinum</option>
												
                                            </select>
										</td>
										<td class="color"><input type="hidden" id="prod2_color1" name="prod2_color1" value="no">
									  </td>
										<td class="quantity"><label class="inline">Qty:</label><input id="prod2_qty1" name="prod2_qty1" type="text" class="number" value="1" class="inline input-mini">
										</td>
										<td class="price">
											<span class="currency">$</span><span class="amount">5000.00</span>
										</td>
										<td class="subtotal">
											<span class="currency">$</span><span class="amount">5000.00</span>
										</td>
										<td class="remove">
                                            <button class="btn btn-danger btn-mini" type="submit" name="prod2_remove1" value="remove_item" rel="tooltip" data-placement="left" data-original-title="Be careful! This item will be entirely removed from the basket!">
                                                <i class="icon-remove icon-white"></i>
                                            </button>
										</td>
									</tr>
									<tr class="warning additional_empty">
										<td class="empty_td" colspan="8">
											
									  </td>
									</tr>
							  </tbody>
					    </table>
                                                
						</div>
						<div class="empty_basket">
							Your Shopping Cart is empty!
						</div>
						<div class="order_blocks clearfix">
							<div class="row">
								<div class="span6 shipping_block clearfix">
									<div class="delivery_block pull-left">
										<h4>Delivery Method</h4>
										<label class="radio">
											<input type="radio" name="deliveryOption" id="deliveryOption1" value="0" checked>
											STANDARD - 4-5 working days: <span class="currency">$</span>0.00
										</label>
										<label class="radio">
											<input type="radio" name="deliveryOption" id="deliveryOption2" value="9.95">
											EXPRESS DELIVERY - 48h: <span class="currency">$</span>9.95
										</label>
									</div>
								</div>
								<div class="span6 total_block">
									<h4>Summary Block</h4>
									<table id="basketTotalsList">
										<tbody>
											<tr>
												<td class="total_position">Goods Subtotal</td>
												<td class="basket_subtotal">
													<span class="currency">$</span><span class="amount">325.67</span>
												</td>
											</tr>
											<tr>
												<td class="total_position">Taxes (<span class="taxes_percent">0</span>%)</td>
												<td class="basket_taxes">
													<span class="currency">$</span><span class="amount">325.67</span>
												</td>
											</tr>
											<tr>
												<td class="total_position">Delivery cost</td>
												<td class="basket_delivery">
													<span class="currency">$</span><span class="amount">325.67</span>
												</td>
											</tr>
											<tr>
												<td class="total_position">Discount (<span class="discount_percent">0</span>%)</td>
												<td class="basket_discount">
													-<span class="currency">$</span><span class="amount">325.67</span>
												</td>
											</tr>
											<tr class="total">
												<td class="total_position">
													<h3>Order Total</h3>
												</td>
												<td class="basket_total">
													<h3>
														<span class="currency">$</span><span class="amount">325.67</span>
													</h3>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
					<div class="navbar">
						<div class="navbar-inner">
							<ul class="nav custom_nav">
								<li class="pull-left">
									<div>
										<a href="http://eyewasframed.co" class="btn btn-info">
											<i class="icon-hand-left icon-white"></i>
											Continue Shopping
										</a>
									</div>
								</li>
								<li class="pull-right">
    <a href="http://eyewasframed.co/checkout.html">
        <span class="btn btn-success continue_to_checkout" type="submit" value="Checkout" name="cont_to_checkout1">
            Continue To Checkout
        </span>
    </a>
</li>
								<li class="pull-right">&nbsp;&nbsp;</li>
								<li class="pull-right">
									<div>
										<button class="btn btn-danger remove_all" type="submit" name="remove_all2" value="remove_all" rel="tooltip" data-placement="top" data-original-title="Be careful! All products will be entirely removed from the basket!">
											<i class="icon-remove icon-white"></i>
											Remove All
										</button>
									</div>
								</li>
							</ul>
						</div>
					</div>
				</div>
			</form>
and the php:

Code: Select all

<?php
try {
    $dbh = new PDO("mysql:host=$hostname;dbname=new_order", $username, $password);
	

$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';


?>

<body>


<?php


if ($_SERVER["REQUEST_METHOD"] == "POST")

{
$errors = [];
}

if(empty($errors)) {
	
	echo "<pre>";
print_r($_POST);
echo "</pre>";
exit;


// prepare sql and bind parameters
    $query = "INSERT INTO details (description, prod2_size1, prod2_qty1, price)
            VALUES (:description, :prod2_size1, :prod2_qty1, :price)";
}
    $stmt = $dbh->prepare($query);
        $stmt->bindParam(':description', $_POST['description']);
        $stmt->bindParam(':prod2_size1', $_POST['prod2_size1']);
        $stmt->bindParam(':prod2_qty1', $_POST['prod2_qty1']);
        $stmt->bindParam(':price', $_POST['price']);
       $stmt->execute();


} catch (PDOException $exception) {
echo $exception->getMessage() . "<br />";
}

/*** close the database connection ***/
$dbh = null;

?>
just point me in the right direction. i'll do my own work. thanks, yall.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: renaming form fields

Post by Celauran »

$_POST should be populated with the contents of the form fields. Your inconsistent indentation makes your code harder to follow, but it looks like you're printing $_POST regardless of request method. Place that code inside the

Code: Select all

if ($_SERVER['REQUEST_METHOD'] == 'POST')
block, submit your form, and post back here.
sladepowers
Forum Newbie
Posts: 6
Joined: Tue Dec 01, 2015 6:34 pm

Re: renaming form fields

Post by sladepowers »

hello all. thanks for all your help. i got it going but couldn't have done it without you.
Post Reply