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.
Related
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.
My goal is to populate a hidden form field with the utm_source from url.
Basically this:
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
The problem is this form works perfectly on one page, but not on another.
Working: museumhack.com/test-a/?utm_source=hello (form field is hidden, but populates value)
Not working: museumhack.com/test-b/?utm_source=hello (at the bottom)
It seems like the pages may be processing the double quotes differently, but not clear how to fix. Wordpress required a plugin to process on page PHP -- I installed that and don't think it's the problem.
Here is the entire form that I copy/pasted between pages:
<form action="http://museumhack.createsend.com/t/d/s/ihhykl/" method="post" id="lead-capture">
<p>
<input id="fieldName" name="cm-name" type="text" placeholder="Your Name"/>
</p>
<p>
<input id="fieldEmail" name="cm-ihhykl-ihhykl" type="email" placeholder="you#email.com" required />
</p>
<p>
<input id="fieldjuuilj" name="cm-f-juuilj" type="text" placeholder="(212)555-5555" />
</p>
<p>
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
</p>
<p>
<button type="submit">Request Quick Quote</button>
</p>
Thanks,
Try this code , this might help you
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET['utm_source']='';?>">
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>
I have a form that looks like so:
<label for="fullpath"><span class="required">*Full Path of folder to change access:</span></label>
<input name="fullpath" id="it10" type="text" size="50" maxlength="50" />
<br />
<small>Example: g:\A\Folder or j:\Your\Folder</small><br />
<div class="bgdiff">
<label for="userpermissiongroup">User Permission Group to be changed:</label>
<input name="userpermissiongroup" type="text" id="it11" size="50" maxlength="50" />
<small>If Known...</small></div>
<br />
<label for="addreadaccess">Additional users requiring read access:</label>
<input name="addreadaccess" type="text" id="it12" size="15" maxlength="15" />
<br />
<small>AD Username</small><br />
<div class="bgdiff">
<label for="addauthoraccess">Additional users requiring author access:</label>
<input name="addauthoraccess" type="text" id="it13" size="12" maxlength="12" />
<br />
<small>AD Username</small></div>
<br />
<label for="removeaccess">Users to be removed from access:</label>
<input name="removeaccess" type="text" id="it14" size="12" maxlength="12" />
<br />
<small>AD Username</small><br />
<div class="bgdiff">
<label for="supervisor"><span class="required">*Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:</span></label>
<input name="supervisor" type="text" id="it15" size="30" maxlength="30" />
<br />
<small>AD Username</small></div>
<br/>
<label for="phoneapprover"><span class="required">*Phone number of approving official: </span></label>
<input name="phoneapprover" type="text" id="it16" size="30" maxlength="30" />
<br />
<small>999-999-9999</small><br />
</fieldset>
</div>
I would like to give users the option to add all of this info to this form more than 1x before submitting. (say 10x max) I have run a couple ideas through my head. 1 is using Javascript to create the new fields and then parse them with my php script somehow. 2 is put say 10 code snips just like the form above in the code and hide them until the user clicks ADD ANOTHER.
Each input needs to be unique as I am submitting this info thought a simple $_REQUEST php script. I understand how to do this with 1 input and a for each loop, but am not sure how to make it work with such a large amount of inputs, labels, etc...
<?php
foreach($_POST['newdata'] as $value) {
echo "$value <br />";
}
?>
Anyone have some suggestions on the best way to go about this? I am not sure adding his form via JS is the best idea, so just displaying the new info from a hidden div seems quicker and easier...
If you append [] to your form field names, PHP will take those fields and turn them into an array, e.g.
<input type="text" name="field[]" value="first" />
<input type="text" name="field[]" value="second" />
<input type="text" name="field[]" value="third" />
would produce the following $_POST structure:
$_POST = array(
'field' => array(
0 => 'first',
1 => 'second',
2 => 'third',
)
);
The alternative is to append incrementing numbers to each field name, as you duplicate the existing field sets for each new block. This provides a nice separation between blocks and allows you guarantee that related fields have the same numerical tag, but it does complicate processing.
It's not so difficult: main idea is to use IDs for each iteration, so your inputs will have unique names and will be processed without problems
for ($i=0;$i<10;$i++){
echo "<input name='removeaccess' type='text' id='it14_{$i}' size='12' maxlength='12' />";
}
So, you take your code of current set of inputs with lables and add to input names IDs, formed on each circle iteration. Be carefull about ' and "!
I have the following code, copied exactly from a exercise from a PHP book. I am having a problem with the value attribute which contains a php echo statement. According to the book, the first time the page is loaded the input boxes should be empty because the variables won't contain any data. Instead, I see something like this:
<br /><b>Notice</b>: Undefined variable: investment in <b>C:\xampp\htdocs\book_apps\ch02_future_value\index.php</b> on line <b>20</b><br />.
Any suggestions?
<form action="display_results.php" method="post">
<div id="data">
<label>Investment Amount:</label>
<input type="text" name="investment"
value="<?php echo $investment; ?>"/><br />
<label>Yearly Interest Rate:</label>
<input type="text" name="interest_rate"
value="<?php echo $interest_rate; ?>"/><br />
<label>Number of Years:</label>
<input type="text" name="years"
value="<?php echo $years; ?>"/><br />
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate"/><br />
</div>
</form>
This is because you are expecting the register_globals directive to be set, while it is not.
This means you have to get $_POST['investement'] instead of $investment and you need to first check if it's been submitted:
$investment = array_key_exists('investment', $_POST) ? $_POST['investment'] : "";