Radio button values not submitting in UCP addition?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Radio button values not submitting in UCP addition?

Post by aster59 » Sun Dec 31, 2017 9:30 pm

I got this code in the template file:

Code: Select all


	<dl>
		<dt>
			<label for="2">{L_UCP_SETTING_TITLE}:</label>
			<span>{L_UCP_SETTING_EXP}.</span>
		</dt>

		<dd>
			<label for="2"><input type="radio" name="a" id="2" value="2" <!-- IF S_UCP_DISPLAY == 2 --> checked="checked" <!-- ENDIF --> >{L_NO_E}</label>

			<label for="1"><input type="radio" name="a" id="1" value="1" <!-- IF S_UCP_DISPLAY == 1 --> checked="checked" <!-- ENDIF --> >{L_MIN_E}</label>

			<label for="0"><input type="radio" name="a" id="0" value="0" <!-- IF S_UCP_DISPLAY == 0 --> checked="checked" <!-- ENDIF --> >{L_MAX_E}</label>
		</dd>
	</dl>

'

I got this code in the event file. This is for the event after submitting changes to UCP and before submitting to UCP:

Code: Select all


public function get_u_setting($event) {

		// add vars for when array comes in
		$event['data'] = array_merge($event['data'], array(
			'current_display'	=> $this->request->variable('display', (int) $this->user->data['display']), //display is value in DB, it is an int(2)
		));

		// Output the data vars to the template (except on form submit)
		if (!$event['submit'])
		{
			$this->template->assign_vars(array(
				'S_UCP_DISPLAY'	=> $event['data']['current_display'],
			));
		}
	}

	public function update_u_setting($event) {

		//die(print_r($event['data']));

		$event['sql_ary'] = array_merge($event['sql_ary'], array(
			'display' => $event['data']['current_display'], //if I change this to a number it works
		));
	}

Then when I check a radio button, it doesn't submit the new value! However, I change $event['data']['current_display'] to a number, it works as shown in comments, so it must be $event['data']['current_display] not changing.

What did I do in my code? Thanks.

User avatar
AbaddonOrmuz
Registered User
Posts: 620
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Radio button values not submitting in UCP addition?

Post by AbaddonOrmuz » Mon Jan 01, 2018 12:15 am

From the code you show, your're not using their values, you radio fields are named a, but you're only requesting a variable named display.

You could also use the $request->variable_names() to see all the variables in the request, I haven't used it myself though.

P.S.: I don't think your IDs should start with numbers.
Some of my phpBB extensions: [ Imgur | SEO Metadata | Markdown ]
Check out all my extensions
Arch Linux user

aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Radio button values not submitting in UCP addition?

Post by aster59 » Mon Jan 01, 2018 2:46 am

AbaddonOrmuz wrote:
Mon Jan 01, 2018 12:15 am
From the code you show, your're not using their values, you radio fields are named a, but you're only requesting a variable named display.

You could also use the $request->variable_names() to see all the variables in the request, I haven't used it myself though.

P.S.: I don't think your IDs should start with numbers.
Ok. You were right about that. I had to make it the DB value too.

Post Reply

Return to “Extension Writers Discussion”