<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Challenges with validating select fields /</title>
		<link>https://legacy.forums.gravityhelp.com/topic/challenges-with-validating-select-fields</link>
		<description>Gravity Support Forums Topic: Challenges with validating select fields /</description>
		<language>en-US</language>
		<pubDate>Tue, 21 Apr 2026 17:27:49 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/challenges-with-validating-select-fields" rel="self" type="application/rss+xml" />

		<item>
			<title>Idealien on "Challenges with validating select fields /"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/challenges-with-validating-select-fields#post-51202</link>
			<pubDate>Sat, 03 Mar 2012 00:04:03 +0000</pubDate>
			<dc:creator>Idealien</dc:creator>
			<guid isPermaLink="false">51202@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;The following will work for custom validation of select fields, to check against ' ' (single space with quotes) and rgpost().&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if( rgpost(&#38;quot;input_19&#38;quot;) == &#38;#39; &#38;#39; ) {
	$validation_result[&#38;#39;is_valid&#38;#39;] = false;
	$field[&#38;#39;failed_validation&#38;#39;] = true;
	$field[&#38;#39;validation_message&#38;#39;] = &#38;#39;This field is required.&#38;#39;;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Idealien on "Challenges with validating select fields /"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/challenges-with-validating-select-fields#post-50510</link>
			<pubDate>Sat, 25 Feb 2012 13:15:22 +0000</pubDate>
			<dc:creator>Idealien</dc:creator>
			<guid isPermaLink="false">50510@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;The following code works to validate a text field (input_25 = City) after checking the value of another that defines what mode the form is being used in (input_27 = City or Event). However trying to do the same thing for a drop-down that has states (Input_19) has not proven to be so kind.&#60;/p&#62;
&#60;p&#62;It will always trip the validation error on the drop-down version regardless of entry. I've tried it in non-enhanced and enhanced mode, with any combination of rgpost() and comparison of values. It is posting to a custom field on the backend when successful.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php function validate_rideshare($validation_result){
 $form = $validation_result[&#38;quot;form&#38;quot;];

 $rideshareFormType = strpos($form[&#38;#39;cssClass&#38;#39;], &#38;#39;idealien_rideshare_gf&#38;#39;);

 if( $rideshareFormType === false &#124;&#124; $validation_result[&#38;quot;is_valid&#38;quot;] === false)
  return $validation_result;

 if( $_POST[&#38;quot;input_27&#38;quot;] == &#38;#39;City&#38;#39; ) {

   foreach($form[&#38;#39;fields&#38;#39;] as $key=&#38;gt;&#38;amp;$field) {

   switch ($field[&#38;#39;postCustomFieldName&#38;#39;]) {

    case &#38;#39;idealien_rideshare_destinationCity&#38;#39;:

      //Destination City
      if( !$_POST[&#38;quot;input_25&#38;quot;] ) {
       $validation_result[&#38;#39;is_valid&#38;#39;] = false;
       $field[&#38;#39;failed_validation&#38;#39;] = true;
       $field[&#38;#39;validation_message&#38;#39;] = &#38;#39;This field is required.&#38;#39;;
      }
     break; 

     /* case &#38;#39;idealien_rideshare_destinationStateProv&#38;#39;:

      //Destination State / Prov
      //**CORE PROBLEM AREA I THINK**
      if( !rgpost(&#38;quot;input_19&#38;quot;) ) {
       $validation_result[&#38;#39;is_valid&#38;#39;] = false;
       $field[&#38;#39;failed_validation&#38;#39;] = true;
       $field[&#38;#39;validation_message&#38;#39;] = &#38;#39;This field is required.&#38;#39;;
      }
     break; */

    }
   }
  }

     $validation_result[&#38;quot;form&#38;quot;] = $form;

     return $validation_result;
 }

?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Reading the docs further it seems like &#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_field_validation&#34; rel=&#34;nofollow&#34;&#62;Gform_field_validation&#60;/a&#62; would be a good candidate for this, but a couple things confused me about it. If showing an example based on that is easy(ier), that would be great.&#60;/p&#62;
&#60;ul&#62;
&#60;li&#62;How to get the non-validated field (input_27 == city) without doing a foreach loop on the $form value.&#60;/li&#62;
&#60;/ul&#62;</description>
		</item>

	</channel>
</rss>
