<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
	<channel>
		<title>cotonti.com : Error handling with Ajax and PHP</title>
		<link>https://www.cotonti.com</link>
		<description>Last topic posts</description>
		<generator>Cotonti</generator>
		<language>en</language>
		<pubDate>Sun, 12 Apr 2026 22:48:13 -0000</pubDate>

		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>OK, got it.</p>

<p>Thanks!</p>
]]></description>
			<pubDate>Sun, 18 Aug 2013 10:05:44 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7502&d=0#post37800]]></link>
		</item>
		<item>
			<title>Trustmaster</title>
			<description><![CDATA[<p>Yes, I check the status and error messages in success function.</p>
]]></description>
			<pubDate>Sun, 18 Aug 2013 06:25:08 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7502&d=0#post37799]]></link>
		</item>
		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>Thanks, Trustmaster! Looks like I sort of was on the right track with my JSON response effort.</p>

<p>I'm guessing you are using this with success: function() {}, as you return 200 regardless?</p>
]]></description>
			<pubDate>Sun, 18 Aug 2013 00:33:07 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7502&d=0#post37797]]></link>
		</item>
		<item>
			<title>Trustmaster</title>
			<description><![CDATA[<p>Here is an example trick that I use:</p>

<pre class="brush:php;">
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$rpost = post_import();
	if (post_validate($rpost, $_POST['name']))
	{
		post_send($rpost);
		$response = array(
			'status'  =&gt; true,
			'message' =&gt; $L['post_message_sent']
		);
	}
	else
	{
		// Return error messages
		$error_fields = array();
		$error_messages = array();
		foreach ($_SESSION['cot_messages'][$sys['site_id']] as $src =&gt; $grp)
		{
			$error_fields[] = $src;
			foreach ($grp as $msg)
			{
				$error_messages[] = isset($L[$msg['text']]) ? $L[$msg['text']] : $msg['text'];
			}
		}
		$response = array(
			'status'         =&gt; false,
			'error_fields'   =&gt; $error_fields,
			'error_messages' =&gt; $error_messages
		);
		cot_clear_messages();
	}

	cot_sendheaders('application/json', '200 OK');

	echo json_encode($response);
}</pre>

<p> </p>
]]></description>
			<pubDate>Sat, 17 Aug 2013 18:00:59 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7502&d=0#post37795]]></link>
		</item>
		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>I'm wondering what in Cotonti the best way is to handle errors with an Ajax submitted form to a PHP file.</p>

<p>Normally with a simple form the errors can be handled with Cotonti's cot_error(); function like this:</p>

<pre class="brush:php;">
cot_error('someErrorMessage', '');
cot_redirect(cot_url('myPlug', 'm=form', '', true));</pre>

<p>How would you guys handle something like this if the form is submitted with Ajax?</p>
]]></description>
			<pubDate>Sat, 17 Aug 2013 14:51:02 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7502&d=0#post37793]]></link>
		</item>
	</channel>
</rss>