Using content from different sources on a page - php

I have a page with mixed sources of content. The top half of it is hard coded html with values echo'd from a db like so:
Part Number: <input type="text" name="pn" size="25" id="1" value="<?php
echo "$STH->pn"; ?>"/>
Part Nomenclature: <input type="text" id="partnomen" name="part_nomenclature"
size="35" value="<?php echo "$STH->part_nomenclature"; ?>"/>
Quantity:<input type="text" name="qty" size="3" value="<?php echo "$STH->qty";
?>"/><br />
Serial Number <input type="text" name="sn" size="25" value="<?php echo "$STH->sn";
?>"/>
ATA Code: <input type="text" name="ata" size="12" value="<?php echo "$STH->ata"; ?>"/>
Control Order: xxxxxx
Engine Model: xxxxxxxx<br />
Engine Serial Number: xxxxxxxx
Removed From A/C Serial# <input type="text" name="acsn" value="<?php echo
"$STH->acsn"; ?>"/>
TT / TC: ___________________-->
<input type="hidden" name="db_date" value="<?php echo "$STH->db_date"; ?>"/>
<h3 id="addinfo">Reason For Workorder: </h3>
The middle contains html and values that are both echo'd onto the page:
echo "
<div id='addlinfo'>
<input type='hidden' name='wo_id' value='$wo_id'/>
Sequence<input type='text' name='sel_id[]' size='1' value='$i'/>
Repair ID:<input type='text' name='repair_id[]' size='1'
value='$STH->repair_id'readonly/>
Part Nomenclature: <input type='text' name='' size='35'
value='$STH->part_nomenclature'readonly/>
Repair Name:<input type='text' name='repair_name[]' size='20'
value='$STH->repair_name' readonly/><br />
Location: <input type='text' name='location[]' size='20' value='$STH->location'
readonly/>
Description:<br /> <textarea id='' rows='5' cols='100' name='description[]'
id='text'>$STH->description</textarea>
</div>";
The bottom half is pulled in from a separate php page using a jquery ajax call like so:
$(document).ready(function(){
$('#button1').click(function(){
$.ajax({
url: 'http://localhost/php_site_copy/process.php',
type: 'POST',
data: {part_name: $('#partnomen').val()},
success: function(msg){
$('#result').html(msg);
}
}); //event handler
});
});
<div id="result"></div><br />
<button id="button1">Add Repairs</button>
The goal here is to collect all of the data displayed into a $_POST from the page but I'm finding that I only get part of the array. The bottom part form elements are not picked up in the post at all and only some of the upper form elements.
You would think that this would work but I'm beginning to think I'm traveling down the wrong road when it comes to mixing content from different sources. Is there a standard that I'm missing or should I just put my nose back to the grindstone?
Edit: to answer quids' question, I'm using Firefox and the form arrangement is like so:
<form action='test_page.php' method='post'/>
<top html inputs/>
<middle inputs/>
<bottom inputs/>
<input type='submit' value='submit'/>
</form>

Related

PHP out putting HTML, better way?

Basically this is what I have:
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
echo "<input type='hidden' name='contactID' value='$contactID'>";
echo "<label>First Name:</label>";
echo "<input type="text" name="fname">";
echo "<label>Last Name:</label>";
echo "<input type="text" name="lname">";
echo "<label>Email:</label>";
echo "<input type="email" name="email">";
echo "<label>Street Address:</label>";
echo "<input type="text" name="streetaddress">";
echo "<label>City:</label>";
echo "<input type="text" name="city">";
echo "<label>Province:</label>";
echo "<input type="text" name="province">";
echo "<label>Postal Code:</label>";
echo "<input type="text" name="postalcode">";
echo "<label>Phone:</label>";
echo "<input type="number" name="phone">";
echo "<label>Date of Birth:</label>";
echo "<input type="date" name="yob">";
echo "<input type="submit" value="Submit Edit">";
?>
</form>
And I think there must be a better way to output html instead of having to output each line with echo, I thought there was a print function to do this but I couldnt find one.
Anyone have a better way of doing this? I know I could do one massive echo but there must still be something better.
I guess this way is better than what I have above but still not looking for a better way.
echo '<label>First Name:</label>.
<input type="text" name="fname">.
<label>Last Name:</label>.
<input type="text" name="lname">.
<label>Email:</label>.
<input type="email" name="email">.
<label>Street Address:</label>.
<input type="text" name="streetaddress">.
<label>City:</label>.
<input type="text" name="city">.
<label>Province:</label>.
<input type="text" name="province">.
<label>Postal Code:</label>.
<input type="text" name="postalcode">.
<label>Phone:</label>.
<input type="number" name="phone">.
<label>Date of Birth:</label>.
<input type="date" name="yob">.
<input type="submit" value="Submit Edit">';
You can switch between PHP and HTML whenever you wish just by adding the appropriate tags.
For example:
<?php
echo "This is output from an echo statement<br>"
?>
This is plain old HTML<br>
<?php
echo "And now we're back to PHP<br>"
Your form becomes:
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
// Do this bit in PHP
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
?>
<!-- Now switch back to HTML -->
<!-- PHP variable embedded here-------------|................| -->
<input type='hidden' name='contactID' value='<?= $contactID?>'>";
<label>First Name:</label>
<input type="text" name="fname">
<label>Last Name:</label>";
<input type="text" name="lname">
<label>Email:</label>
<input type="email" name="email">
<!-- and so on -->
</form>
<?php
// You can store long text strings in HEREDOC or NOWDOC syntax
$longString = <<<'EOT'
This is an arbitrarily long string, but this one is only short<br>
EOT
echo $longString;
See the PHP manual for all the details on how PHP handles strings, HEREDOC, NOWDOC, and the significance of single and double quotes.

populate input field with PHP variable

I am creating a pizza ordering site with php. Now I want to echo the variable passed through the URL within the form. I know how to retrieve this data: <?php echo $_GET["numpizzas"]; ?>. But I don't know the proper way to add it to my html form field. any help is much appreciated
<?php
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="<?php echo "hi"; ?>" >
//Money field does not populate with number, I just see <?php echo $_GET[
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
?>
<?php echo $_GET["numpizzas"]; ?>
I also tried storing the integer in a variable $howmanypizzas = $_GET["numpizzas"]; ?>but it still doesn't show up as the field value.
<?php echo $_GET["numpizzas"]; ?> does not only retrieve the data. echo also outputs it to the html response (the screen)
since you are allready passing your html with an ECHO, you can do:
<?php
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="'.$_GET["numpizzas"].'" >
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
?>
Explanation: echo is a function that recieves a string and outputs it to html.
So, with the concatenation operator . you can inject the $_GET["numpizzas"] variable into your html, as a string, and pass it to the echo function, wich outputs it to the browser.
Another way to solve it is to only invoke PHP where you need to process your logic, just like #pavithra answer, wich also works.
You're already echoing and trying to echo inside of that. You need to concatenate your variable with the string that you are echoing, see PHP Strings:
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="' . $_GET["numpizzas"] . '">
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
You might also consider Heredoc syntax.
<input type="text" name="money" value="<?php echo $_GET["numpizzas"]; ?>" />
but i dont get why do you get this is as a get variable.hope this works
<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label> <input type="text" name="money" value="<?php echo $_GET["numpizzas"]; ?>" />
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>

the referrer relay response or receipt link url is invalid

After transaction got successful at authorize.net SIM method it is not redirecting to my website URL. I am getting the error message
the referrer relay response or receipt link url is invalid
Here is my code of my transaction page which is submitting information. Please let me know my mistake in it.
<!-- Create the HTML form containing necessary SIM post values -->
<form method="post" id="finalform" action="<?php echo $url; ?>" >
<!-- Additional fields can be added here as outlined in the SIM integration guide
at: http://developer.authorize.net -->
<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<input type='hidden' name='x_amount' onkeyup="gethash(this.value);" value='<?php echo $amount; ?>' /><br/>
<input type='hidden' name='x_description' value='<?php echo $description; ?>' />
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' /><br/>
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<input type='hidden' name='x_fp_hash' id="fphash" value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<input type='hidden' name="x_first_name" value="<?php echo $_REQUEST['fne'];?>" />
<input type='hidden' name="x_last_name" value="<?php echo $_REQUEST['lne'];?>" />
<input type='hidden' name="x_company" value="<?php echo $_REQUEST['orgme'];?>" />
<input type='hidden' name="x_address" value="<?php echo $_REQUEST['adds'];?>" />
<input type='hidden' name="x_city" value="<?php echo $_REQUEST['cty'];?>" />
<input type='hidden' name="x_state" value="<?php echo $_REQUEST['ste'];?>" />
<input type='hidden' name="x_zip" value="<?php echo $_REQUEST['zip'];?>" />
<input type='hidden' name="x_cust_id" value="<?php echo $_REQUEST['cusd'];?>" />
<input type="hidden" name="x_receipt_link_method" value="LINK" >
<input type="hidden" name="x_receipt_link_url" value="http://www.uthstuph.com/payment-success/" >
<input type="hidden" name="x_relay_response" value="TRUE" >
<input type="hidden" name="x_relay_url" value="http://www.uthstuph.com/payment-success" >
<input type="hidden" name="x_phone" value="<?php echo $_REQUEST['phone'];?>"/>
<input type="hidden" name="x_email" value="<?php echo $_REQUEST['email'];?>"/>
<input type="hidden" name="x_billing_zip" value="<?php echo $_REQUEST['x_billing_zip'];?>"/>
<input type="hidden" value="<?php echo $_REQUEST['cno'];?>" autocomplete="off" maxlength="16" name="x_card_num" id="x_card_num" class="input_text"><br/>
<input type="hidden" value="<?php echo $_REQUEST['cexp'];?>" autocomplete="off" maxlength="20" name="x_exp_date" id="x_exp_date" class="input_text">
<input type="hidden" name="x_card_code" value="<?php echo $_REQUEST['ccode'];?>"/>
</form>
<script type="text/javascript">
document.getElementById("finalform").submit();
</script>
IN ACCOUNT SETTING I set
Default Receipt URL : http://www.uthstuph.com/payment-success/
Default Relay Response URL : http://www.uthstuph.com/payment-success/
I have tried both http as well as https.
Thanks in advance.
From the Authorize.net support page:
Error 14 may also occur if you try to submit x_receipt_link_url and
x_relay_url simultaneously, instead of choosing a receipt method.
Remove one of them and they should work. Also, from your Authorize.net account try the following:
To add a valid Response/Receipt URL:
Log into the Merchant Interface at https://account.authorize.net.
Click Account from the main toolbar.
Click Response/Receipt URLs under
Transaction Format Settings.
Click Add URL.
Enter your Response URL.
Click Submit

One form and two actions and two submit in php

Wokring on a project where the user have the ability to chose from date and to date, and then chose one of the radio buttoms. After that chose pdf or excel to generate the to preferred format.
The problem is the form, I want it to action generateExcel.php if excel is pressed and generatePdf.php if PDF is pressed. This is how far I have came and not working yet:
<form action='generatePdf.php' method='Post'/>
Fra Dato: <input type="text" name="fraDato" value="<?php echo date('d-m-Y'); ?>" />
Til Dato: <input type="text" name="tilDato" value="<?php echo date('d-m-Y'); ?>"> <br>
<input type="radio" name="hent" value="timesmaling">Times malinger<br>
<input type="radio" name="hent" value="tredjetimesmaling">Tredje times malinger <br>
<input type="radio" name="hent" value="oppgaver">Oppgaver <br>
<input type="radio" name="hent" value="dagvakt">Dagvakt <br>
<input type="radio" name="hent" value="kveldsvakt">Kveldsvakt <br>
<input type="radio" name="hent" value="kontrollcm">Kontroll CM <br>
<input type='submit' name='pdf' value='PDF'>
<form action='generateExcel.php' method='Post'/>
<input type='submit' name='excel' value='excel'>
</form>
It is possible to override the action attribute of the parent form using the HTML5 formaction attribute on a button. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
<input type='submit' name='pdf' value='PDF' formaction='generatePdf.php'>
<input type='submit' name='excel' value='excel' formaction='generateExcel.php'>
The browser support looks pretty good: http://www.wufoo.com/html5/attributes/13-formaction.html
However, webeno's answer would definitely work in all browsers and it can be easier to manage all your form processing code in one file.
I'd recommend you to put both of your scripts on the same file and validate against the button that has been clicked.
EDIT: If your 2 files are too big (or you would like to keep them separate for any other reason), you could still use include (or require - more info on the differences: Difference between "include" and "require" in php).
original file:
<form action='generate.php' method='Post'> <!-- removed the slash from the end here -->
Fra Dato: <input type="text" name="fraDato" value="<?php echo date('d-m-Y'); ?>" />
Til Dato: <input type="text" name="tilDato" value="<?php echo date('d-m-Y'); ?>"> <br>
<input type="radio" name="hent" value="timesmaling">Times malinger<br>
<input type="radio" name="hent" value="tredjetimesmaling">Tredje times malinger <br>
<input type="radio" name="hent" value="oppgaver">Oppgaver <br>
<input type="radio" name="hent" value="dagvakt">Dagvakt <br>
<input type="radio" name="hent" value="kveldsvakt">Kveldsvakt <br>
<input type="radio" name="hent" value="kontrollcm">Kontroll CM <br>
<input type='submit' name='pdf' value='PDF'>
<input type='submit' name='excel' value='excel'>
</form>
generate.php:
if (isset($_POST['pdf'])) {
include('generatePdf.php');
}
if (isset($_POST['excel'])) {
include('generateExcel.php');
}
EDITED
Alternatively you could just use redirect on that separate file (generate.php - make sure there is nothing else on this page):
if (isset($_POST['pdf'])) {
header('Location: generatePdf.php');
}
if (isset($_POST['excel'])) {
header('Location: generateExcel.php');
}

Tab order for php-based elements in a form

I currently have a form that has a few elements that are php-based. In the form, these php-based elements are skipped over when I tab through the form. How do I set the tab order for a php-based element in a form?
Here is a subset of the code. I want the tab order of billing country to be 13 (in between zip and phone).
<div class="controls"><input placeholder="Zip Code" name="billing_zip" tabindex="12" type="text" class="medium" id="billing_zip" value="<?php echo $order['billing']['zip']; ?>" /></div>
<div class="controls"><?php echo country_box($order['billing']['country'], "billing_country"); //echo Html::state_box($order['billing']['state'], 'billing_state', 'state custom mini', array('display' => 'abbrev', 'display_case' => 'upper', 'optional' => true));?></div>
<div class="controls"><input placeholder="Phone" name="billing_phone" tabindex="14" type="text" id="billing_phone" value="<?php echo $order['billing']['phone']; ?>"/></div>
To really do this properly, you should be generating all of this HTML using a PHP script or function. However, if that is not possible or is too much trouble, you can at least use PHP to keep track of the tab index, and using a PHP variable like $tab_index to echo and increment like tab_index++;. An example:
<?php
$tab_index = 1;
?>
<input ... name='zip' tabindex='<?php echo $tab_index; $tab_index++; ?> type='text' />
<input ... name='country' tabindex='<?php echo $tab_index; $tab_index++; ?> type='text' />
<input ... name='phone' tabindex='<?php echo $tab_index; $tab_index++; ?> type='text' />
With each ++, the tabindex will be updated and the next one correctly shown as incremented.

Categories