Restricting a Form Submission

7 posts by 3 authors in: Forums > CMS Builder
Last Post: August 20, 2012   (RSS)

By gkornbluth - August 20, 2012

Hi All,

I could use a little help from a coding guru.

I’ve created a submission form that’s only for use by registered users who are not members of an organization. (Their user account has a field with the value of ‘non_member’)

For a field in that form I’m pulling the options from an array of ‘title’ values from a multi record table (Master Exhibition List).

Each record in the Master Exhibition List table has only two fields, a text field called ‘title’ and a check box called ‘members_only’. Both are required fields.

What I need to accomplish is to only allow the form to be submitted if the value of the ‘members_only’ check box that matches the option value chosen by the user is ‘0'.

If it's ‘1', I’d need to display: $errorsAndAlerts = This exhibition only accepts submissions from members.

The entire viewer is attached, but the code that pulls the 'title' options from the ‘Master Exhibition List’ table is:
<?php
$names = array();
foreach ($master_exhibition_listRecords as $record){
$names[$record['title']]=$record['title'];
}
?>


And the field in the form is:
<option value=""><span class="body-text-bold">Select an Exhibition Name</span></option>

<?php foreach($names as $name): ?>
<option value="<?php echo $name;?>"><?php echo $name;?></option>
<?php endforeach?>
</select>


I started messing with this but don’t know where to go with it.
<?php
$member_only = array();
foreach ($master_exhibition_listRecords as $record){
$member_only[$record['member_only']]=$record['member_only'];
}
?>


Any ideas?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [nmsinc] Restricting a Form Submission

By gkornbluth - August 20, 2012 - edited: August 20, 2012

Hi nmsink,

Thanks for looking at this, but in this case I don't think your approach will work. I'm tying the " members only" to a value that relates to a the specific exhibition pulled from the Master Exhibition List, not as a global value for the user.

However, once I've figured out what code needs to be in the "if" to meet the criteria, that's pretty much the format that I'll use to limit the submission.

Thanks again,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Restricting a Form Submission

By Jason - August 20, 2012

Hi Jerry,

I think your best bet would be to limit the options in the drop down to non member records. It can be confusing to offer up and option that will never be accepted.

How about this:

<select class="validate[required]" type="text" id="project_title" name="project_title">
<option value=""><span class="body-text-bold">Select an Exhibition Name</span></option>
<?php foreach(mysql_select("master_exhibition_records", "member_only = '0'") as $exhibitionRecord): ?>
<option value="<?php echo $exhibitionRecord['title'];?>"><?php echo $exhibitionRecord['title'];?></option>

<?php endforeach?>
</select>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Restricting a Form Submission

By gkornbluth - August 20, 2012

What a simple and elegant solution.

One minor fix.

How would I add a second criteria to the members_only ='0'.

I'd like to add hidden = '0' so that the hidden records don't show in the options.

<?php foreach(mysql_select("master_exhibition_list", "members_only = '0'") as $exhibitionRecord): ?>

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Restricting a Form Submission

By Jason - August 20, 2012

Hi Jerry,

Give this a try:

<?php foreach(mysql_select("master_exhibition_list", "members_only = '0' AND hidden = '0' ") as $exhibitionRecord): ?>

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Restricting a Form Submission

By gkornbluth - August 20, 2012

Thanks Jason,

I had the " in the wrong place and was using && instead of AND.

Works great now.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php