Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Script to Ignore Placeholder Text in Input Fields
    text
    copied!<p>I have the following script called <strong>form.php</strong>: <a href="http://pastebin.com/kHiZ3gLY" rel="nofollow">http://pastebin.com/kHiZ3gLY</a> (I have pasted full script below)</p> <p>When I complete the first set of 4 fields (leaving the other 2 sets with their placeholder text) and submit, my <strong>var_dump</strong> output is:</p> <pre><code>string '1|1|1|1 Height (cm)|Width (cm)|Length (cm)|Weight (kg) Height (cm)|Width (cm)|Length (cm)| ' (length=133) </code></pre> <p>Is it possible that I can use PHP/jQuery to "ignore" the fields that have the placeholder text in place? So my output would just be:</p> <pre><code>string '1|1|1|1' (length=7) </code></pre> <p>Many thanks for any helpers here.</p> <p><strong>full script:</strong></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"&gt; &lt;head profile="http://gmpg.org/xfn/11"&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;title&gt;March 2012 Experiment&lt;/title&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="http://digitalbush.com/files/jquery/watermarkinput/beta1/jquery.watermarkinput.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(function($){ $("#p1height").Watermark("Height (cm)"); $("#p1width").Watermark("Width (cm)"); $("#p1length").Watermark("Length (cm)"); $("#p1weight").Watermark("Weight (kg)"); $("#p2height").Watermark("Height (cm)"); $("#p2width").Watermark("Width (cm)"); $("#p2length").Watermark("Length (cm)"); $("#p2weight").Watermark("Weight (kg)"); $("#p3height").Watermark("Height (cm)"); $("#p3width").Watermark("Width (cm)"); $("#p3length").Watermark("Length (cm)"); $("#p3weight").Watermark("Weight (kg)"); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $errors = ''; if (isset($_POST['submitform'])) { $ierrors = array(); $all = ''; // Loop over the values 1 through 3 foreach( range( 1, 3) as $i) { // Create an array that stores all of the values for the current number $values = array( 'p' . $i . 'height' =&gt; $_POST['p' . $i . 'height'], 'p' . $i . 'width' =&gt; $_POST['p' . $i . 'width'], 'p' . $i . 'length' =&gt; $_POST['p' . $i . 'length'], 'p' . $i . 'weight' =&gt; $_POST['p' . $i . 'weight'] ); // Validate every value foreach( $values as $key =&gt; $value) { if( empty( $value)) { $ierrors[] = "Value $key is not set"; } // You can add more validation in here, such as: if( !is_numeric( $value)) { $ierrors[] = "Value $key contains an invalid value '$value'"; } } // Join all of the values together to produce the desired output $all .= implode( '|', $values) . "\n\n"; } var_dump($all); } ?&gt; &lt;form action="form.php" method="post"&gt; &lt;input type="text" id="p1weight" name="p1weight" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p1length" name="p1length" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p1width" name="p1width" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p1height" name="p1height" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;input type="text" id="p2weight" name="p2weight" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p2length" name="p2length" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p2width" name="p2width" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p2height" name="p2height" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;input type="text" id="p3weight" name="p3weight" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" value="" id="p3length" name="p3length" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" value="" id="p3width" name="p3width" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;input type="text" id="p3height" name="p3height" value="" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;input type="submit" name="submitform" id="submitform" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload