close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validated Entries In PHP Loop

Thread began 11/28/2012 3:12 pm by Cologne | Last modified 11/29/2012 9:55 am by Jason Byrnes | 4300 views | 6 replies |

Cologne

Validated Entries In PHP Loop

Hello,

I create my year select field with a for loop.
How can I make it selected with the Validation Entries Form Element.

<select name="year" id="year">
<option value="0">Year</option>
<?php
for($y=date('Y'); $y>=date('Y')-100; $y--){ ?>
<option value="<?php echo $y; ?>"><?php echo $y; ?></option>
<?php } ?>
</select>



Cheers,
Denis

Sign in to reply to this post

Jason ByrnesWebAssist

you will need to hand code it.

change:

php:
<?php

        
for($y=date('Y'); $y>=date('Y')-100$y--){ ?>
        <option value="<?php echo $y?>"><?php echo $y?></option>
        <?php ?>



to:

php:
<?php 

        
for($y=date('Y'); $y>=date('Y')-100$y--){ ?>
        <option value="<?php echo $y?><?php if (!(strcmp($y, (ValidatedField("pagename","year"))))) {echo "selected=\"selected\"";} ?>><?php echo $y?></option>
        <?php ?>
Sign in to reply to this post

Cologne

Hi Jason,

perfect, works fine!

Thanks a lot!
Denis

Sign in to reply to this post

Cologne

Hi Jason,

is there a way I can use numbers like 01,02,03 for month, so they fit in the database style.
I validate them with the date/time server behavior yyyy-mm-dd

But this does not work with.

<select name="month" id="month">
<option value="0" <?php if (!(strcmp(0, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Monat</option>
<option value="1" <?php if (!(strcmp(1, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Januar</option>
<option value="2" <?php if (!(strcmp(2, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Februar</option>
<option value="3" <?php if (!(strcmp(3, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>März</option>
<option value="4" <?php if (!(strcmp(4, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>April</option>
<option value="5" <?php if (!(strcmp(5, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Mai</option>
<option value="6" <?php if (!(strcmp(6, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Juni</option>
<option value="7" <?php if (!(strcmp(7, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Juli</option>
<option value="8" <?php if (!(strcmp(8, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>August</option>
<option value="9" <?php if (!(strcmp(9, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Sptember</option>
<option value="10" <?php if (!(strcmp(10, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Oktober</option>
<option value="11" <?php if (!(strcmp(11, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>November</option>
<option value="12" <?php if (!(strcmp(12, (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Dezember</option>
</select>



if I do it with simple nubers my age check doesnt work cause auf the choosen yyyy-mm-dd

If I use 01,02,03 the Validation Entries doesnt work anymore :-(

Sign in to reply to this post

Jason ByrnesWebAssist

make sure the comparison value is in quotes, for example:

php:
<option value="00" <?php if (!(strcmp("00", (ValidatedField("registerstep1_250","month"))))) {echo "selected=\"selected\"";} ?>>Monat</option>
Sign in to reply to this post

Cologne

Hmm, this does not work.

here is my validation code:

$WAFV_Errors .= WAValidateDT(((isset($_POST["year"]))?$_POST["year"]:"").'-'.((isset($_POST["month"]))?$_POST["month"]:"").'-'.((isset($_POST["day"]))?$_POST["day"]:"") . "",true,"\b\d{4}-(1[0-2]|0[1-9])-([12]\d|3[0-1]|0[1-9])\b","","".(date("Y-m-d", mktime(0, 0, 0,  date("d"), date("m"), date("Y") - 18)))  ."",false,".*","","",true,8);



And this is the Server Variable

((isset($_POST["year"]))?$_POST["year"]:"").'-'.((isset($_POST["month"]))?$_POST["month"]:"").'-'.((isset($_POST["day"]))?$_POST["day"]:"")



The Value for Day and Month I did like you said.

<option value="0" <?php if (!(strcmp(0, (ValidatedField("registerstep1_250","day"))))) {echo "selected=\"selected\"";} ?>>Tag</option>
<option value="01" <?php if (!(strcmp("01", (ValidatedField("registerstep1_250","day"))))) {echo "selected=\"selected\"";} ?>>1</option>
<option value="02" <?php if (!(strcmp("02", (ValidatedField("registerstep1_250","day"))))) {echo "selected=\"selected\"";} ?>>2</option>
<option value="03" <?php if (!(strcmp("03", (ValidatedField("registerstep1_250","day"))))) {echo "selected=\"selected\"";} ?>>3</option>



I think its the format, used in the Date/Time validation yyyy-mm-dd

something is wrong.

If I do it with a simple textfield it works, cause the user enters the right format yyyy-mm-dd

Sign in to reply to this post

Jason ByrnesWebAssist

you started a new thread for this here:
showthread.php?p=141713&posted=1#post141713

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...