The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form dropdown list
#1
Hi

I would like to have a dropdown list in a form in US 4.2.9. How can I create this? Is it as simple as using HTML select? Keep in mind I don't have any PHP knowledge.

Thanks
Pierre
  Reply
#2
You got it!

Simple as an HTML Select.

Similar to a name or ID for a input of text, it will only take the value you select as the value for this input.

Let me know if you have any questions.
  Reply
#3
Yep. If you need help, don't be afraid to ask.

Also, since you're new, you'll probably want this primer on using Php to work with the database.

https://youtu.be/rb0kD5tCENM
  Reply
#4
Great, thanks mudmin.
  Reply
#5
I'm afraid I'm getting stuck. Here's where I am:
<label for="street">Residential address* (e.g. 1)</label>
<SELECT class="form-control" name="streetlist" form="payment-form">
<option value=""></option>
<option value="Street1">1</option>
<option value="Street2">2</option>
</SELECT>
<input class="form-control" maxlength="13" type="text" name="street" id="street" value="<?php if (!$form_valid && !empty($_POST)){ echo $street;} ?>" required >

I made the 1st <option> blank as an attempt to have the person select a street instead of leaving it at default.

The page still displays the original input field AND now a select box. So I remove the <input> section leaving:
<label for="street">Residential address* (e.g. 1)</label>
<SELECT class="form-control" name="streetlist" form="payment-form">
<option value=""></option>
<option value="Street1">1</option>
<option value="Street2">2</option>
</SELECT>

Now I've lost the php required validation. Some more messing around and found this to work:
<label for="street">Residential address* (e.g. 1 Douglas Carr)</label>
<SELECT class="form-control" name="streetlist" form="payment-form" value="<?php if (!$form_valid && !empty($_POST)){ echo $street;} ?>" required >
<SELECT class="form-control" name="streetlist" form="payment-form">
<option value=""></option>
<option value="Street1">1</option>
<option value="Street2">2</option>
</SELECT>

Problem solved. Happiness. Well, almost Smile
  Reply
#6
OK, problem not solved. On testing my solution above:
<label for=”street”>Residential address* (e.g. 1 Douglas Carr)</label>
<SELECT class=”form-control” name=”streetlist” form=”payment-form” value=”<?php if (!$form_valid && !empty($_POST)){ echo $street;} ?>” required >
<SELECT class=”form-control” name=”streetlist” form=”payment-form”>
<option value=””></option>
<option value=”Street1″>1</option>
<option value=”Street2″>2</option>
</SELECT>

I now get error "Street is required". This is presumably because the php required check is before the <select>.
I'm in your hands, folks - how to get the <select> to work with validation? I will need the exact code I think.

Thanks!
  Reply
#7
One thing you should do is add the "required" attribute to your select:
Code:
<select class="form-control" name="streetlist" form="payment-form" required >

Your validation imo should just be required, like this:
http://pasted.co/31fbd8f5
  Reply
#8
Thanks Brandin but that did not do the trick.

I added a couple of fields to users/views/_join.php
Added these fields in users/join.php as well.

I pasted users/join.php here
http://pasted.co/71955765

users/views/_join.php here
http://pasted.co/5779c6fa

Thanks for your help so far!
  Reply
#9
As a test I commented out the <select> and reverted to the <input>. That works. So the problem is only with the <select> portion.
  Reply
#10
Your issue is that you did call the inputs in your post

Right after the post opens you see things like
Code:
$username = Input::get('username')
- you need to re-create these for the other things you added.
  Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)